Skip to content

Commit

Permalink
doc: clarify that import also uses main
Browse files Browse the repository at this point in the history
PR-URL: nodejs#41720
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
benmccann authored Jan 30, 2022
1 parent 3dd3a3c commit 253f934
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions doc/api/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 253f934

Please sign in to comment.