[Bug?]: cannot import chai from a module using PNP
See original GitHub issueSelf-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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yes
I’ll leave this open until the PR is merged