doc: clarify that import also uses main
PR-URL: https://github.com/nodejs/node/pull/41720 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
parent
3dd3a3cc20
commit
253f934462
@ -1093,17 +1093,19 @@ added: v0.4.0
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `"main"` field defines the script that is used when the [package directory
|
The `"main"` field defines the entry point of a package when imported by name
|
||||||
is loaded via `require()`](modules.md#folders-as-modules). Its value
|
via a `node_modules` lookup. Its value is a path.
|
||||||
is a path.
|
|
||||||
|
When a package has an [`"exports"`][] field, this will take precedence over the
|
||||||
|
`"main"` field when importing the package by name.
|
||||||
|
|
||||||
|
It also defines the script that is used when the [package directory is loaded
|
||||||
|
via `require()`](modules.md#folders-as-modules).
|
||||||
|
|
||||||
```cjs
|
```cjs
|
||||||
require('./path/to/directory'); // This resolves to ./path/to/directory/main.js.
|
require('./path/to/directory'); // This resolves to ./path/to/directory/main.js.
|
||||||
```
|
```
|
||||||
|
|
||||||
When a package has an [`"exports"`][] field, this will take precedence over the
|
|
||||||
`"main"` field when importing the package by name.
|
|
||||||
|
|
||||||
### `"packageManager"`
|
### `"packageManager"`
|
||||||
|
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
|
Loading…
x
Reference in New Issue
Block a user