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: #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 and danielleadams committed Mar 14, 2022
1 parent 20d9c4a commit 211a3c4
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 @@ -1138,17 +1138,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 211a3c4

Please sign in to comment.