File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
commonjs-extension-resolution-loader Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change 1+ Node's ESM specifier resolution does not support all default behavior of
2+ the CommonJS loader. One of the behavior differences is automatic resolution
3+ of file extensions and the ability to import directories that have an index
4+ file.
5+
6+ Use this loader to enable automatic extension resolution and importing from
7+ directories that include an index file, like this:
8+
9+ ``` js
10+ import file from ' ./file' ; // Where ./file is ./file.js or ./file.mjs
11+ import index from ' ./folder' ; // Where ./folder is ./folder/index.js or ./folder/index.mjs
12+ ```
13+
14+ This loader also applies these automatic resolution rules to the program entry point passed to ` node ` on the command line:
15+
16+ ``` console
17+ $ node index.mjs
18+ success!
19+ $ node index # Failure!
20+ Error: Cannot find module
21+ $ node --loader=./loader.js index
22+ success!
23+ ```
You can’t perform that action at this time.
0 commit comments