enhanced-resolve icon indicating copy to clipboard operation
enhanced-resolve copied to clipboard

Problem with exports

Open pauldraper opened this issue 2 years ago • 5 comments

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)

pauldraper avatar Oct 20 '21 15:10 pauldraper

What is version? No exports https://github.com/rollup/rollup-pluginutils/blob/master/package.json

alexander-akait avatar Oct 20 '21 15:10 alexander-akait

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.)

pauldraper avatar Oct 20 '21 15:10 pauldraper

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');

alexander-akait avatar Oct 20 '21 15:10 alexander-akait

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).

pauldraper avatar Oct 20 '21 15:10 pauldraper

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

alexander-akait avatar Oct 20 '21 16:10 alexander-akait