@@ -834,12 +834,12 @@ The following fields in `package.json` files are used in Node.js: |
834 | 834 |
|
835 | 835 | * [`"name"`][] - Relevant when using named imports within a package. Also used |
836 | 836 | 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. |
837 | 839 | * [`"type"`][] - The package type determining whether to load `.js` files as |
838 | 840 | CommonJS or ES modules. |
839 | 841 | * [`"exports"`][] - Package exports and conditional exports. When present, |
840 | 842 | 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. |
843 | 843 | * [`"imports"`][] - Package imports, for use by modules within the package |
844 | 844 | itself. |
845 | 845 |
|
@@ -871,6 +871,30 @@ _npm_ registry requires a name that satisfies |
871 | 871 | The `"name"` field can be used in addition to the [`"exports"`][] field to |
872 | 872 | [self-reference][] a package using its name. |
873 | 873 |
|
| 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 | + |
874 | 898 | ### `"type"` |
875 | 899 | <!-- YAML |
876 | 900 | added: v12.0.0 |
@@ -882,6 +906,8 @@ changes: |
882 | 906 | description: Unflag `--experimental-modules`. |
883 | 907 | --> |
884 | 908 |
|
| 909 | +> Stability: 1 - Experimental |
| 910 | + |
885 | 911 | * Type: {string} |
886 | 912 |
|
887 | 913 | The `"type"` field defines the module format that Node.js uses for all |
@@ -948,6 +974,8 @@ changes: |
948 | 974 | description: Implement conditional exports. |
949 | 975 | --> |
950 | 976 |
|
| 977 | +> Stability: 1 - Experimental |
| 978 | + |
951 | 979 | * Type: {Object} | {string} | {string[]} |
952 | 980 |
|
953 | 981 | ```json |
@@ -969,30 +997,6 @@ referenced via `require` or via `import`. |
969 | 997 | All paths defined in the `"exports"` must be relative file URLs starting with |
970 | 998 | `./`. |
971 | 999 |
|
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 | | - |
996 | 1000 | ### `"imports"` |
997 | 1001 | <!-- YAML |
998 | 1002 | added: v14.6.0 |
|