enhanced-resolve
enhanced-resolve copied to clipboard
Problem with exports
I'm not sure what the nature of the problem is, but the @rollup/pluginutils
package won't resolve.
npm init
npm i @rollup/[email protected]
Node.js succeeds:
require.resolve('@rollup/pluginutils');
.../node_modules/@rollup/pluginutils/dist/cjs/index.js
enhanced-require fails:
require('enhanced-resolve').sync(process.cwd(), '@rollup/pluginutils');
Error: Package path . is not exported from package .../node_modules/@rollup/pluginutils (see exports field in .../node_modules/@rollup/pluginutils/package.json)
What is version
? No exports
https://github.com/rollup/rollup-pluginutils/blob/master/package.json
See install command; version is 3.1.0.
https://github.com/rollup/plugins/blob/master/packages/pluginutils/package.json
(And enhanced-resolve version is 5.8.3.)
Oh, by default enhanced-resolve
is loading only default
or node
conditionals (because we don't know nothing about esm/commonjs, because it is programmatic usage), but no default
and no node
in package.json
, we strongly recommend always add default
(but maybe out of scope your abilities), you can use:
require('enhanced-resolve').create.sync({ conditionNames: ["require", "node"] })(process.cwd(), '@rollup/pluginutils');
Excellent that worked. Thanks for the fast help!
I don't know enough to say what is "at fault" but for my case, I am looking to match Node.js require.resolve
(I'm not bundling for a browser or anything).
The main problem when you use require.resolve
Node.js known that you in commonjs, so can use require
, but when you use programmatic API we don't known about it