Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: clarify fallback behavior of module require #22494

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,22 +352,22 @@ If this was in a folder at `./some-library`, then

This is the extent of Node.js's awareness of `package.json` files.

If the file specified by the `'main'` entry of `package.json` is missing and
can not be resolved, Node.js will report the entire module as missing with the
default error:

```txt
Error: Cannot find module 'some-library'
```

If there is no `package.json` file present in the directory, then Node.js
If there is no `package.json` file present in the directory, or if the
`'main'` entry is missing or cannot be resolved, then Node.js
will attempt to load an `index.js` or `index.node` file out of that
directory. For example, if there was no `package.json` file in the above
example, then `require('./some-library')` would attempt to load:

* `./some-library/index.js`
* `./some-library/index.node`

If these attempts fail, then Node.js will report the entire module as missing
with the default error:

```txt
Error: Cannot find module 'some-library'
```

## Loading from `node_modules` Folders

<!--type=misc-->
Expand Down