create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

React-scripts test command not working

Open Huespal opened this issue 4 years ago • 19 comments

Describe the bug

react-scripts test command stopped working after update to ^4.0.3 from ^3.0.0.

It shows this error on terminal:

● Validation Error:

  Watch plugin jest-watch-typeahead/filename cannot be found. Make sure the watchPlugins configuration option points to an existing node module.

  Configuration Documentation:
  https://jestjs.io/docs/configuration.html

error Command failed with exit code 1.

Nothing has changed on the code. Only react-scripts package. Tests were working fine before the update. The project is not ejected and it is not intended to be.

Did you try recovering your dependencies?

Yes, I tried. yarn version: 1.22.10

Which terms did you search for in User Guide?

I've search for 'react-scripts test' and 'watchPlugins' and all I found is that I need to eject the project. I don't understand why. It was never like that. So I think that is not the solution to the problem.

Steps to reproduce

  1. Open a terminal on the CRA project root
  2. Run yarn
  3. Run yarn test

Expected behavior

I expect tests run fine. Like before updating to ^4.0.3.

Actual behavior

react-scripts test command stops working after update react-scripts library to ^4.0.3 from ^3.0.0.

It shows this error on terminal:

● Validation Error:

  Watch plugin jest-watch-typeahead/filename cannot be found. Make sure the watchPlugins configuration option points to an existing node module.

  Configuration Documentation:
  https://jestjs.io/docs/configuration.html

error Command failed with exit code 1.

Thank you :D

Huespal avatar Jun 01 '21 08:06 Huespal

Same Problem here

aschuermann-at-neusta avatar Jun 10 '21 07:06 aschuermann-at-neusta

Running into this as well.

Elliot128 avatar Jun 23 '21 20:06 Elliot128

facing the same issue.

kkgowtamasa avatar Jul 01 '21 06:07 kkgowtamasa

I've fixed it by installing the plugin jest-watch-typeahead

Warix3 avatar Jul 06 '21 12:07 Warix3

I've fixed it by installing the plugin jest-watch-typeahead

Work for me!!! Thanks

danpadua avatar Jul 29 '21 15:07 danpadua

Same here. Could be yarn issue?

MiroslavPetrik avatar Jul 30 '21 06:07 MiroslavPetrik

I've fixed it by installing the plugin jest-watch-typeahead

Thank you!

k61b avatar Jul 30 '21 11:07 k61b

Repro

I've also run into this same situation with a CRA currently, non-ejected, with react-scripts 4.0.3, though I reproduced it for 4.0.x in general. Same situation where I'm running the following inside my CRA:

  • yarn
  • yarn test

and then getting the same error:

Validation Error:

Watch plugin jest-watch-typeahead/filename cannot be found. Make sure the watchPlugins configuration option points to an existing node module.

Configuration Documentation:
https://jestjs.io/docs/configuration.html

Jest Config

Since this is through CRA, the only jest config options in my package.json are essentially:

"jest": {
    "testMatch": [
      "**/__tests__/**/*.test.[jt]s?(x)"
    ],
    "transformIgnorePatterns": [
      "<rootDir>/node_modules/(?!@private-repo-name)/"
    ]
  },

Running yarn test with additional options such as below causes the same validation error: yarn react-scripts test --testPathPattern App.test.tsx

Application Structure

I suspect that this might be related to the structure of this application, as I've recently changed it.

Here's a simplified diagram of the (full-stack) project:

Root (express server)

📦 my-preexisting-project
|_ 📁 client // see below for structure ⬇️
|_ 📁 routes
|_ 📁 server
|_ 📁 test // currently empty 😞 😞 😞
|_ 📄  package.json
|_ 📄  babel.config.js, webpack.config.js, (...)

Client Application (made with latest CRA)

📦 client
|_ 📁 public
|_ 📁 src
|  |_ 📁 "__tests__"
|  |  |_ 📁 components
|  |  |_ 📁 setup // helpers surfaced by setupTests.tsx
|  |  |_ 📄 App.test.tsx
|  |_ 📁 assets
|  |_ 📁 components
|  |_ 📁 integrations
|  |_ 📁 pages
|  |_ 📁 utils
|_ 📄 package.json
|_ 📄 setupTests.tsx
|_ 📄 tsconfig.json, .env, (...)

Anyway, apologies in advance if I'm missing something simple (tooling/build stuff for full-stack apps is a bit new for me, and this project predates my work on it), but I mostly just wanted to document another case of this. If I find a work-around, fix, etc., I'll be sure to return and share for others.

seanmhanson avatar Oct 06 '21 15:10 seanmhanson

I have had the same issue and one important thing to notice is that the newest released version of jest-watch-typeahead is now written in native ESM and will break with the following error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

Make sure to install the version compatible with Jest 26 e non native ESM modules.

yarn add --exact [email protected]

ggwzrd avatar Oct 13 '21 16:10 ggwzrd

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar Jan 09 '22 06:01 stale[bot]

same problem here

MarcelDurganteDev avatar Feb 08 '22 17:02 MarcelDurganteDev

Hello. I created a related issue. After adding the correct jest-watch-typeahead v.0.6.5 package as @giuliogallerini pointed out, the problems continues. Thank you.

Huespal avatar Mar 10 '22 14:03 Huespal

I noticed that I didn't have jest-watch-typeahead in my node_modules. Installing it solved the problem:

npm install --save-dev jest-watch-typeahead

That's a workaround of course rather than solving the problem.

dooman87 avatar Mar 13 '22 11:03 dooman87

any update with this issue?

wulinjie122 avatar May 10 '22 23:05 wulinjie122

Encountered same issue

jasonaravanis avatar May 31 '22 06:05 jasonaravanis

I didn't have the issue when moving to 4.0.3, but saw the issue when going to 5.0.0

Just found a linked issue that relates to my issue: https://github.com/facebook/create-react-app/issues/11792

shiraze avatar Jul 04 '22 13:07 shiraze

Encountered same issue

The issue has to do with your node version. Update your node to the latest stable version to fix it.

user2695 avatar Sep 03 '22 05:09 user2695

I had the same error and I found a work around.

npm i -D --exact [email protected]

then there'll be an error for the jest version, I changed it to version 27.0.0, same the ts-jest.

gmmvllfrt avatar Sep 09 '22 11:09 gmmvllfrt

Had the same issue after updating react-scripts 4.0.35.0.1.

It's not necessary to add jest-watch-typeahead as a dependency to the package.json, no-save install was enough in my case: npm install --no-save [email protected]

Running npm ci might be more robust solution, though.

edloidas avatar Sep 13 '22 07:09 edloidas