GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — doc: update package.json field definitions · nodejs/node@6590f8c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • packages.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/packages.md‎

Copy file name to clipboardExpand all lines: doc/api/packages.md
+30-26Lines changed: 30 additions & 26 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.