From 30b91f79f9e431f3c105d05525fe217b793521cb Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Tue, 18 Oct 2022 13:09:14 -0700 Subject: [PATCH 1/2] Create README.md Copied and pasted from the old documentation for `--experimental-specifier-resolution` --- commonjs-extension-resolution-loader/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 commonjs-extension-resolution-loader/README.md diff --git a/commonjs-extension-resolution-loader/README.md b/commonjs-extension-resolution-loader/README.md new file mode 100644 index 0000000..84fa9ab --- /dev/null +++ b/commonjs-extension-resolution-loader/README.md @@ -0,0 +1,16 @@ +Node's ESM specifier resolution does not support all default behavior of +the CommonJS loader. One of the behavior differences is automatic resolution +of file extensions and the ability to import directories that have an index +file. + +Use this loader to enable automatic extension resolution and importing from +directories that include an index file. + +```console +$ node index.mjs +success! +$ node index # Failure! +Error: Cannot find module +$ node --loader=./loader.js index +success! +``` From e35e7a3ce77facb5c15795a8a146aa4df0804522 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Tue, 18 Oct 2022 13:50:47 -0700 Subject: [PATCH 2/2] Document `import` statements --- commonjs-extension-resolution-loader/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/commonjs-extension-resolution-loader/README.md b/commonjs-extension-resolution-loader/README.md index 84fa9ab..eb3028b 100644 --- a/commonjs-extension-resolution-loader/README.md +++ b/commonjs-extension-resolution-loader/README.md @@ -4,7 +4,14 @@ of file extensions and the ability to import directories that have an index file. Use this loader to enable automatic extension resolution and importing from -directories that include an index file. +directories that include an index file, like this: + +```js +import file from './file'; // Where ./file is ./file.js or ./file.mjs +import index from './folder'; // Where ./folder is ./folder/index.js or ./folder/index.mjs +``` + +This loader also applies these automatic resolution rules to the program entry point passed to `node` on the command line: ```console $ node index.mjs