Skip to content

Commit 6590f8c

Browse files
MylesBorinstargos
authored andcommitted
doc: update package.json field definitions
Only imports has the experimental status right now but technically all ESM related features are currently experimental. The list also doesn't appear to be in any specific order so I've grouped the experimental features together. PR-URL: #35741 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Derek Lewis <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]>
1 parent 66da122 commit 6590f8c

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

doc/api/packages.md

+30-26
Original file line numberDiff line numberDiff line change
@@ -834,12 +834,12 @@ The following fields in `package.json` files are used in Node.js:
834834

835835
* [`"name"`][] - Relevant when using named imports within a package. Also used
836836
by package managers as the name of the package.
837+
* [`"main"`][] - The default module when loading the package, if exports is not
838+
specified, and in versions of Node.js prior to the introduction of exports.
837839
* [`"type"`][] - The package type determining whether to load `.js` files as
838840
CommonJS or ES modules.
839841
* [`"exports"`][] - Package exports and conditional exports. When present,
840842
limits which submodules can be loaded from within the package.
841-
* [`"main"`][] - The default module when loading the package, if exports is not
842-
specified, and in versions of Node.js prior to the introduction of exports.
843843
* [`"imports"`][] - Package imports, for use by modules within the package
844844
itself.
845845

@@ -871,6 +871,30 @@ _npm_ registry requires a name that satisfies
871871
The `"name"` field can be used in addition to the [`"exports"`][] field to
872872
[self-reference][] a package using its name.
873873

874+
### `"main"`
875+
<!-- YAML
876+
added: v0.4.0
877+
-->
878+
879+
* Type: {string}
880+
881+
```json
882+
{
883+
"main": "./main.js"
884+
}
885+
```
886+
887+
The `"main"` field defines the script that is used when the [package directory
888+
is loaded via `require()`](modules.md#modules_folders_as_modules). Its value
889+
is a path.
890+
891+
```js
892+
require('./path/to/directory'); // This resolves to ./path/to/directory/main.js.
893+
```
894+
895+
When a package has an [`"exports"`][] field, this will take precedence over the
896+
`"main"` field when importing the package by name.
897+
874898
### `"type"`
875899
<!-- YAML
876900
added: v12.0.0
@@ -882,6 +906,8 @@ changes:
882906
description: Unflag `--experimental-modules`.
883907
-->
884908

909+
> Stability: 1 - Experimental
910+
885911
* Type: {string}
886912

887913
The `"type"` field defines the module format that Node.js uses for all
@@ -948,6 +974,8 @@ changes:
948974
description: Implement conditional exports.
949975
-->
950976

977+
> Stability: 1 - Experimental
978+
951979
* Type: {Object} | {string} | {string[]}
952980

953981
```json
@@ -969,30 +997,6 @@ referenced via `require` or via `import`.
969997
All paths defined in the `"exports"` must be relative file URLs starting with
970998
`./`.
971999

972-
### `"main"`
973-
<!-- YAML
974-
added: v0.4.0
975-
-->
976-
977-
* Type: {string}
978-
979-
```json
980-
{
981-
"main": "./main.js"
982-
}
983-
```
984-
985-
The `"main"` field defines the script that is used when the [package directory
986-
is loaded via `require()`](modules.md#modules_folders_as_modules). Its value
987-
is interpreted as a path.
988-
989-
```js
990-
require('./path/to/directory'); // This resolves to ./path/to/directory/main.js.
991-
```
992-
993-
When a package has an [`"exports"`][] field, this will take precedence over the
994-
`"main"` field when importing the package by name.
995-
9961000
### `"imports"`
9971001
<!-- YAML
9981002
added: v14.6.0

0 commit comments

Comments
 (0)