Jest-puppeteer: Fresh install doesn't work

Created on 18 Apr 2018  ·  6Comments  ·  Source: smooth-code/jest-puppeteer

  • Install jest globally with 'npm install -g jest'
  • Create a directory and cd into it
  • Put into package.json:
{
  "jest": {
    "preset": "jest-puppeteer"
  }
}
  • npm install --save-dev jest-puppeteer puppeteer
    Note this warning is printed:
npm 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.

  • Put sample code into test.js
  • 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.

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?

Most helpful comment

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:

  • Create a directory and cd into it
  • Put into package.json:
{
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "preset": "jest-puppeteer"
  }
}
  • npm install --save-dev jest-puppeteer puppeteer
    Note this warning is printed:
npm 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.

  • Put sample code into test.js
  • 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.

All 6 comments

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:

  • Create a directory and cd into it
  • Put into package.json:
{
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "preset": "jest-puppeteer"
  }
}
  • npm install --save-dev jest-puppeteer puppeteer
    Note this warning is printed:
npm 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.

  • Put sample code into test.js
  • 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.

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

macabeus picture macabeus  ·  4Comments

undrafted picture undrafted  ·  4Comments

ifiokjr picture ifiokjr  ·  5Comments

FezVrasta picture FezVrasta  ·  4Comments

paperbackdragon picture paperbackdragon  ·  4Comments