Skip to content

Commit 391b65f

Browse files
Merge pull request #13 from dfabulich/patch-1
2 parents 985a3c7 + e35e7a3 commit 391b65f

File tree

1 file changed

+23
-0
lines changed
  • commonjs-extension-resolution-loader

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
```

0 commit comments

Comments
 (0)