playwright-community / playwright-jest-examples

Demonstrates the usage of Playwright (cross-browser automation library in Node.js) in combination with Jest on GitHub Actions to test various setups.

Home Page:https://playwright.tech

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to run the create-react-app-coverage example

ocavue opened this issue · comments

I'm testing the create-react-app-coverage and when I run npm run test, react-scripts throws an error:

The react-scripts package provided by Create React App requires a dependency:

  "jest": "26.6.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of jest was detected higher up in the tree

Here is how I run this command:

+ codespace ➜ /tmp $ git clone https://github.com/playwright-community/playwright-jest-examples.git
Cloning into 'playwright-jest-examples'...
remote: Enumerating objects: 79, done.
remote: Counting objects: 100% (79/79), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 287 (delta 46), reused 57 (delta 41), pack-reused 208
Receiving objects: 100% (287/287), 165.36 KiB | 776.00 KiB/s, done.
Resolving deltas: 100% (150/150), done.
codespace ➜ /tmp $ cd playwright-jest-examples
+ codespace ➜ /tmp/playwright-jest-examples (master) $ git log --oneline -n 1
9979025 (HEAD -> master, origin/master, origin/HEAD) chore: bump Playwright to 1.9.0 (#20)
+ codespace ➜ /tmp/playwright-jest-examples (master) $ node --version
v14.15.1
+ codespace ➜ /tmp/playwright-jest-examples (master) $ npm --version
6.14.8
+ codespace ➜ /tmp/playwright-jest-examples (master) $ cd create-react-app-coverage/
+ codespace ➜ /tmp/playwright-jest-examples/create-react-app-coverage (master) $ npm install 
added 1907 packages from 832 contributors and audited 1912 packages in 30.189s

137 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

+ codespace ➜ /tmp/playwright-jest-examples/create-react-app-coverage (master) $ npm run test

 > create-react-app-coverage@0.1.0 test /tmp/playwright-jest-examples/create-react-app-coverage
 > jest -c jest.config.js && nyc report --reporter=lcovonly


Jest dev-server output:
[Jest Process Manager] 
 > create-react-app-coverage@0.1.0 start /tmp/playwright-jest-examples/create-react-app-coverage
 > react-app-rewired start


There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

  "jest": "26.6.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of jest was detected higher up in the tree:

  /tmp/playwright-jest-examples/create-react-app-coverage/node_modules/jest (version: 26.6.3) 

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "jest" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
     This may help because npm has known issues with package hoisting which may get resolved in future versions.

  6. Check if /tmp/playwright-jest-examples/create-react-app-coverage/node_modules/jest is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls jest in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed jest.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! create-react-app-coverage@0.1.0 start: `react-app-rewired start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the create-react-app-coverage@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/codespace/.npm/_logs/2021-03-21T15_21_06_446Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! create-react-app-coverage@0.1.0 test: `jest -c jest.config.js && nyc report --reporter=lcovonly`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the create-react-app-coverage@0.1.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/codespace/.npm/_logs/2021-03-21T15_21_06_486Z-debug.log
+ codespace ➜ /tmp/playwright-jest-examples/create-react-app-coverage (master) $ 

It seems that the GitHub Action workflow doesn't have this issue (I tried to special the node.js version to v14 in the GitHub Action workflow and it didn't throw any error). I don't know what is the difference between the CI environment and my local environment that causes this.

Closed since the Next.js example seems like what you want. Yep the React examples with cra are not ideal!