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:
Ben McCann 2022-01-30 06:26:22 -08:00 committed by GitHub
parent 3dd3a3cc20
commit 253f934462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1093,17 +1093,19 @@ added: v0.4.0
}
```
The `"main"` field defines the script that is used when the [package directory
is loaded via `require()`](modules.md#folders-as-modules). Its value
is a path.
The `"main"` field defines the entry point of a package when imported by name
via a `node_modules` lookup. Its value 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
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"`
<!-- YAML