Skip to content

Commit 211a3c4

Browse files
benmccanndanielleadams
authored andcommitted
doc: clarify that import also uses main
PR-URL: #41720 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 20d9c4a commit 211a3c4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

doc/api/packages.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,17 +1138,19 @@ added: v0.4.0
11381138
}
11391139
```
11401140

1141-
The `"main"` field defines the script that is used when the [package directory
1142-
is loaded via `require()`](modules.md#folders-as-modules). Its value
1143-
is a path.
1141+
The `"main"` field defines the entry point of a package when imported by name
1142+
via a `node_modules` lookup. Its value is a path.
1143+
1144+
When a package has an [`"exports"`][] field, this will take precedence over the
1145+
`"main"` field when importing the package by name.
1146+
1147+
It also defines the script that is used when the [package directory is loaded
1148+
via `require()`](modules.md#folders-as-modules).
11441149

11451150
```cjs
11461151
require('./path/to/directory'); // This resolves to ./path/to/directory/main.js.
11471152
```
11481153

1149-
When a package has an [`"exports"`][] field, this will take precedence over the
1150-
`"main"` field when importing the package by name.
1151-
11521154
### `"packageManager"`
11531155

11541156
<!-- YAML

0 commit comments

Comments
 (0)