Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package path . is not exported from package #283

Closed
martpie opened this issue Feb 8, 2021 · 8 comments
Closed

Package path . is not exported from package #283

martpie opened this issue Feb 8, 2021 · 8 comments

Comments

@martpie
Copy link

martpie commented Feb 8, 2021

Hello 👋

While trying to solve martpie/next-transpile-modules#147, I realized the problem was most probably coming from enhanced-resolve.

Here's a snippet:

const enhancedResolve = require('enhanced-resolve');
const process = require('process');

const resolve = enhancedResolve.create.sync();

console.log(resolve(process.cwd(), 'nanoid'));

And the stack trace is:

/Users/pierre/dev/test-ntm-nanoid/node_modules/enhanced-resolve/lib/Resolver.js:246
		if (err) throw err;
		         ^

Error: Package path . is not exported from package /Users/pierre/dev/test-ntm-nanoid/node_modules/nanoid (see exports field in /Users/pierre/dev/test-ntm-nanoid/node_modules/nanoid/package.json)
    at /Users/pierre/dev/test-ntm-nanoid/node_modules/enhanced-resolve/lib/ExportsFieldPlugin.js:104:7
    at Hook.eval [as callAsync] (eval at create (/Users/pierre/dev/test-ntm-nanoid/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:22:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/pierre/dev/test-ntm-nanoid/node_modules/tapable/lib/Hook.js:18:14)
    at Resolver.doResolve (/Users/pierre/dev/test-ntm-nanoid/node_modules/enhanced-resolve/lib/Resolver.js:407:16)
    at /Users/pierre/dev/test-ntm-nanoid/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:74:17
    at /Users/pierre/dev/test-ntm-nanoid/node_modules/enhanced-resolve/lib/DescriptionFileUtils.js:118:13
    at /Users/pierre/dev/test-ntm-nanoid/node_modules/enhanced-resolve/lib/forEachBail.js:16:12
    at onJson (/Users/pierre/dev/test-ntm-nanoid/node_modules/enhanced-resolve/lib/DescriptionFileUtils.js:108:6)
    at /Users/pierre/dev/test-ntm-nanoid/node_modules/enhanced-resolve/lib/DescriptionFileUtils.js:68:7
    at SyncAsyncFileSystemDecorator.readJson (/Users/pierre/dev/test-ntm-nanoid/node_modules/enhanced-resolve/lib/SyncAsyncFileSystemDecorator.js:89:25)

nanoid's exports field looks like this:

Screen Shot 2021-02-08 at 11 07 19

Any idea what could go wrong exactly? Am I misusing enhanced-resolve?

cheers!

@sokra
Copy link
Member

sokra commented Feb 8, 2021

There is no default condition in the exports field and you didn't specify any conditions in the resolver (conditionNames option)

@martpie
Copy link
Author

martpie commented Feb 8, 2021

Great, thank you! I will forward that to the maintainer of nanoid!

@sokra
Copy link
Member

sokra commented Feb 8, 2021

You need to pass the conditions that applies in your use case. E.g. import if this is a request from an import.

@martpie
Copy link
Author

martpie commented Feb 8, 2021

Thank you for the tip!

@ai
Copy link

ai commented Feb 8, 2021

@sokra what file we should use default export section?

@sokra
Copy link
Member

sokra commented Feb 8, 2021

Note that's not wrong to not have a default, we just recommend to have one as fallback for unforeseen and future cases.

Here is a note about that in our guide:
https://webpack.js.org/guides/package-exports/#common-patterns
Reading the whole guide is also interesting, but it's pretty long...

Anyway here you can change imports to default.

@ai
Copy link

ai commented Mar 15, 2021

I added default and browser.default to dual-publish and re-released Nano ID

ai/dual-publish@a85c242

@martpie
Copy link
Author

martpie commented Mar 15, 2021

Thank you very much @ai !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants