question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
merceyzcommented, Oct 31, 2021

The “entrypoint” is mocha, right?

Yes

0reactions
merceyzcommented, Nov 2, 2021

I’ll leave this open until the PR is merged

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix "cannot use import statement outside a module"
This error occurs for one reason: you're trying to use import and you're not inside an ES module. It can happen in a...
Read more >
Mocha + TypeScript: Cannot use import statement outside a ...
I created the app using TypeScript and CommonJS module to transpile, so I added "test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' ...
Read more >
How to Fix "SyntaxError: Cannot use import statement outside ...
In this post, we'll learn more about the "SyntaxError: Cannot use import statement outside a module" error and how to fix it in...
Read more >
Getting started with unit testing SPFx - Microsoft 365 PnP
With this command we will add jest and types for jest (our unit testing ... { assert } from "chai"; import { GraphDocumentsProvider...
Read more >
jest encountered an unexpected token ts-jest - You.com
With the latest version of ts-jest I'm getting this error when importing Angular ... SyntaxError: Cannot use import statement outside a module at...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found