cd into itpackage.json:{
"jest": {
"preset": "jest-puppeteer"
}
}
npm install --save-dev jest-puppeteer puppeteernpm WARN [email protected] requires a peer of jest-environment-node@^22.0.0 but none is installed. You must install peer dependencies yourself.
Also note that node_modules/jest-environment-node doesn't exit.
jest test.js gives this error:~/repro-issues (jest): jest test.js
FAIL ./test.js
● Test suite failed to run
Cannot find module 'jest-environment-node'
at Object.<anonymous> (node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:9:28)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.05s, estimated 3s
Ran all test suites matching /test.js/i.
npm install --save-dev [email protected]. Now jest test.js works.This happens because of this peer dependency. With npm, peer dependencies must be manually installed. This SO answer explains when to use peer dependencies.
@neoziro, can these be regular dependencies instead of peer?
I thought that jest-environment-node was installed with jest that's why it is a peer dependency. I will check but if it is not the case it makes sense to add move it into dependencies.
Ah, I did an npm global install of jest. (Updated my repro steps.) So even if jest installed jest-environment-node, it wouldn't be in <root_dir>/node_modules.
Can you further explain the technical reason why the peer dependency was needed? Or just try getting rid of the peer dependencies? There's also a peer dependency in packages/jest-puppeteer/package.json; it would be nice to get rid of that too.
I have just tested to install jest locally and it installs jest-environment-node/. Installing jest globally is not a good practice, so please install it locally and everything will work.
Even without jest global, fresh install doesn't work. You either need to add jest-environment-node to the npm install command, or take out peer dependencies. Why not take out peer dependencies, they just complicate things?
Repro steps without global jest:
cd into itpackage.json:{
"scripts": {
"test": "jest"
},
"jest": {
"preset": "jest-puppeteer"
}
}
npm install --save-dev jest-puppeteer puppeteernpm WARN [email protected] requires a peer of jest-environment-node@^22.0.0 but none is installed. You must install peer dependencies yourself.
Also note that node_modules/jest-environment-node doesn't exit.
jest test.js gives this error:npm test
FAIL ./test.js
● Test suite failed to run
Cannot find module 'jest-environment-node'
at Object.<anonymous> (node_modules/jest-environment-puppeteer/lib/PuppeteerEnvironment.js:9:28)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.05s, estimated 3s
Ran all test suites matching /test.js/i.
npm install --save-dev [email protected]. Now npm test works.@melissachang
Even with jest global
I think @neoziro expressly said to not use jest globally but locally and everything will work 😋
I haven't tested myself.
Sorry, I meant "even without jest global", I edited the post.
Most helpful comment
Even without jest global, fresh install doesn't work. You either need to add
jest-environment-nodeto thenpm installcommand, or take out peer dependencies. Why not take out peer dependencies, they just complicate things?Repro steps without global jest:
cdinto itpackage.json:npm install --save-dev jest-puppeteer puppeteerNote this warning is printed:
Also note that
node_modules/jest-environment-nodedoesn't exit.jest test.jsgives this error:npm install --save-dev [email protected]. Nownpm testworks.