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 <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
benmccann authored and ruyadorno committed Feb 7, 2022
1 parent 4889a31 commit 86644b9
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 86644b9

Please sign in to comment.