Cannot find module 'cheerio' from 'node_modules/enzyme/build/Utils.js' #2518
Open
Description
I just start receiving this message to my unit tests today, although it was working fine before
Cannot find module 'cheerio' from 'node_modules/enzyme/build/Utils.js'
Require stack:
node_modules/enzyme/build/Utils.js
node_modules/enzyme/build/ShallowWrapper.js
node_modules/enzyme-to-json/utils.js
node_modules/enzyme-to-json/createSerializer.js
node_modules/enzyme-to-json/serializer.js
at Resolver.resolveModule (node_modules/jest-runtime/node_modules/jest-resolve/build/index.js:306:11)
at Object.<anonymous> (node_modules/enzyme/src/Utils.js:9:1)
Is there anything changed in serlizer.js?
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"enzyme-to-json": "^3.6.1",
Metadata
Assignees
Labels
No labels
Activity
ljharb commentedon May 6, 2021
enzyme-to-json
is not maintained by the enzyme team, so you'd have to ask them.Mahdiyeh commentedon May 7, 2021
Same here for me:
`
Cannot find module 'cheerio' from 'node_modules/enzyme/build/Utils.js'
My dependencies:
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.5"
ljharb commentedon May 7, 2021
Please try pinning cheerio to
=1.0.0.rc-3
, ensure it's installed, and let me know if the issue persists.rxgx commentedon May 20, 2022
Adding an override doesn't fix the issue with
enzyme
incorrectly using a loose RC pattern for a hard dependency.ljharb commentedon May 20, 2022
@rxgx while that should work - file an issue with npm if it doesn't - simply adding
"cheerio": "=1.0.0.rc-3"
to yourdevDependencies
should be sufficient, no overrides required.rxgx commentedon May 20, 2022
@ljharb what old version of npm are you using?
ljharb commentedon May 20, 2022
works fine with every version of npm, through the latest. That's a version specifier, not a tag name.
It's what the next release of enzyme will use: https://github.com/enzymejs/enzyme/blob/master/packages/enzyme/package.json#L42
rxgx commentedon May 20, 2022
Is it possible that this version is missing from the registry? I get these errors even with
rm node_modules
andnpm cache verify
. OR something up with npm itselfljharb commentedon May 20, 2022
Is it possible you're not using the public registry? It's quite there: https://unpkg.com/browse/cheerio@1.0.0-rc.3/
rxgx commentedon May 20, 2022
Here's what I originally thought was the resolution before being derailed by the invalid
=
syntax. I got the hyphen and dots mixed up.If you manually change the version of the
dependencies
ordevDependencies
, your lock file is unfortunately going to be out of sync.ljharb commentedon May 20, 2022
The = syntax is a range; overrides takes a specific version - it’s not invalid in general, i just wasn’t providing an override. Overrides should be used only as a last resort.
nspector commentedon May 20, 2022
Looks like the change to pin it here: cafdb2b
was never published: https://unpkg.com/browse/enzyme@3.11.0/package.json. Can somebody publish it? Thank you!
ljharb commentedon May 20, 2022
@nspector correct; it hasn't been published yet. it'll be in the next release.
Again, you can get the benefit now merely by doing
npm install --save-dev cheerio@=1.0.0-rc.3
.tonnyskk commentedon May 21, 2022
Try lock your
cheerio
version to1.0.0-rc.10
E.g. by yarn resolutions.1.0.0-rc.11
will throw the error.billnbell commentedon May 22, 2022
This worked for me
25 remaining items