You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because commonjs-extension-resolution-loader relies on resolve/async which is an implementation of require.resolve(), specifying it as a Node.js loader causes ESM packages to break.
For example,
index.js
importisValidAbnfrom'is-valid-abn';
works fine with node --experimental-specifier-resolution=node index.js, but with node --experimental-loader=./commonjs-extension-resolution-loader index.js breaks with:
file:///…/index.js:2
import isValidAbn from 'is-valid-abn';
^^^^^^^^^^
SyntaxError: The requested module 'is-valid-abn' does not provide an export named 'default'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:530:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
What makes the error go away:
Monkey patching main field in is-valid-abn's package.json to point to ESM entry file
Monkey patching resolve package to include:
if(pkg&&pkg.module){if(typeofpkg.module!=='string'){varmainError=newTypeError('package “'+pkg.name+'” `main` must be a string');mainError.code='INVALID_PACKAGE_MAIN';returncb(mainError);}if(pkg.module==='.'||pkg.module==='./'){pkg.module='index';}loadAsFile(path.resolve(x,pkg.module),pkg,function(err,m,pkg){if(err)returncb(err);if(m)returncb(null,m,pkg);if(!pkg)returnloadAsFile(path.join(x,'index'),pkg,cb);vardir=path.resolve(x,pkg.module);loadAsDirectory(dir,pkg,function(err,n,pkg){if(err)returncb(err);if(n)returncb(null,n,pkg);loadAsFile(path.join(x,'index'),pkg,cb);});});return;}
This, obviously, doesn't get the support for exports field back.
The text was updated successfully, but these errors were encountered:
Because commonjs-extension-resolution-loader relies on
resolve/async
which is an implementation of require.resolve(), specifying it as a Node.js loader causes ESM packages to break.For example,
index.js
works fine with
node --experimental-specifier-resolution=node index.js
, but withnode --experimental-loader=./commonjs-extension-resolution-loader index.js
breaks with:What makes the error go away:
main
field inis-valid-abn
'spackage.json
to point to ESM entry fileresolve
package to include:This, obviously, doesn't get the support for
exports
field back.The text was updated successfully, but these errors were encountered: