diff options
author | TomCoded <tomtinkerer@gmail.com> | 2018-08-22 16:28:18 -0700 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-09-02 13:50:06 +0200 |
commit | 594dd4242b99824d44b2b0f17421fa86c10f1d12 (patch) | |
tree | 5444dff98a1fd76d6108eddc03f802c5c4f1da18 /doc/api/modules.md | |
parent | 208022cb313209000ca490628fc3f03e392671aa (diff) | |
download | android-node-v8-594dd4242b99824d44b2b0f17421fa86c10f1d12.tar.gz android-node-v8-594dd4242b99824d44b2b0f17421fa86c10f1d12.tar.bz2 android-node-v8-594dd4242b99824d44b2b0f17421fa86c10f1d12.zip |
doc: clarify fallback behavior of module require
PR-URL: https://github.com/nodejs/node/pull/22494
Fixes: https://github.com/nodejs/node/issues/22464
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: George Adams <george.adams@uk.ibm.com>
Diffstat (limited to 'doc/api/modules.md')
-rw-r--r-- | doc/api/modules.md | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/doc/api/modules.md b/doc/api/modules.md index bdff1ab1f1..f7934706d6 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -352,15 +352,8 @@ 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: @@ -368,6 +361,13 @@ 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--> |