Skip to content

Commit 7d8ef42

Browse files
TomCodedtargos
authored andcommitted
doc: clarify fallback behavior of module require
PR-URL: #22494 Fixes: #22464 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: George Adams <[email protected]>
1 parent 48648f5 commit 7d8ef42

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

doc/api/modules.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,22 @@ If this was in a folder at `./some-library`, then
352352

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

355-
If the file specified by the `'main'` entry of `package.json` is missing and
356-
can not be resolved, Node.js will report the entire module as missing with the
357-
default error:
358-
359-
```txt
360-
Error: Cannot find module 'some-library'
361-
```
362-
363-
If there is no `package.json` file present in the directory, then Node.js
355+
If there is no `package.json` file present in the directory, or if the
356+
`'main'` entry is missing or cannot be resolved, then Node.js
364357
will attempt to load an `index.js` or `index.node` file out of that
365358
directory. For example, if there was no `package.json` file in the above
366359
example, then `require('./some-library')` would attempt to load:
367360

368361
* `./some-library/index.js`
369362
* `./some-library/index.node`
370363

364+
If these attempts fail, then Node.js will report the entire module as missing
365+
with the default error:
366+
367+
```txt
368+
Error: Cannot find module 'some-library'
369+
```
370+
371371
## Loading from `node_modules` Folders
372372

373373
<!--type=misc-->

0 commit comments

Comments
 (0)