Skip to content

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

@nemanja-tosic

Description

@nemanja-tosic

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingesm

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions