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

[Bug?]: cannot import chai from a module using PNP #3671

Closed
1 task done
nemanja-tosic opened this issue Oct 29, 2021 · 5 comments · Fixed by #3667
Closed
1 task done

[Bug?]: cannot import chai from a module using PNP #3671

nemanja-tosic opened this issue Oct 29, 2021 · 5 comments · Fixed by #3667
Labels
bug Something isn't working esm

Comments

@nemanja-tosic
Copy link

Self-service

  • I'd be willing to implement a fix

Describe the bug

Importing chai from a module:

import { expect } from 'chai';

leads to:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'chai' imported from /home/ntosic/Projects/yarn-issues/test/dummy.spec.js
Did you mean to import chai-npm-4.3.4-808f3b5355-772c522b3b.zip/node_modules/chai/index.js?
    at new NodeError (internal/errors.js:322:7)
    at packageResolve (internal/modules/esm/resolve.js:687:9)
    at moduleResolve (internal/modules/esm/resolve.js:728:18)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:842:11)
    at Loader.resolve (internal/modules/esm/loader.js:89:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:76:40)
    at link (internal/modules/esm/module_job.js:75:36)

To reproduce

git clone --branch module-pnp-chai git@github.com:livingspec/yarn-issues.git
cd yarn-issues
yarn
yarn test

Environment

System:
    OS: Linux 5.14 Fedora 33 (KDE Plasma) 33 (KDE Plasma)
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 14.18.1 - /tmp/xfs-888edaa2/node
    Yarn: 3.1.0 - /tmp/xfs-888edaa2/yarn
    npm: 6.14.15 - /usr/bin/npm

Additional context

No response

@nemanja-tosic nemanja-tosic added the bug Something isn't working label Oct 29, 2021
@merceyz
Copy link
Member

merceyz commented Oct 29, 2021

Note that ESM support is experimental; however this is fixed by #3667, you can verify by running

yarn set version from sources --branch 3667 && yarn && yarn test

@teohhanhui
Copy link

teohhanhui commented Oct 31, 2021

#3667 mentions:

when the entrypoint is also a commonjs module

But I thought this issue is about trying to import chai from an ESM? (i.e. "type": "module" in package.json or using .mjs extension)

EDIT: Uhh, I think I understand now... The "entrypoint" is mocha, right?

@merceyz
Copy link
Member

merceyz commented Oct 31, 2021

The "entrypoint" is mocha, right?

Yes

@nemanja-tosic
Copy link
Author

#3667 appears to fix the issue, so i'll keep an eye out for when it's either in master or for a new release. Thanks!

@merceyz
Copy link
Member

merceyz commented Nov 2, 2021

I'll leave this open until the PR is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working esm
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants