'Failed to initialize watch plugin' when running tests for newly created app
See original GitHub issueDescribe the bug
Running tests (using npm test
) for a newly created app throws the error:
Error: Failed to initialize watch plugin "node_modules/jest-watch-typeahead/filename.js":
● Test suite failed to run
file:///Users/dannyskoog/GIT/test-version-5/node_modules/jest-watch-typeahead/build/file_name_plugin/prompt.js:4
import { PatternPrompt, printPatternCaret, printRestoredPatternCaret } from 'jest-watcher';
^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'printPatternCaret' not found. The requested module 'jest-watcher' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'jest-watcher';
const { PatternPrompt, printPatternCaret, printRestoredPatternCaret } = pkg;
at async requireOrImportModule (node_modules/jest-util/build/requireOrImportModule.js:65:32)
at async watch (node_modules/@jest/core/build/watch.js:337:34)
at async _run10000 (node_modules/@jest/core/build/cli/index.js:311:7)
at async runCLI (node_modules/@jest/core/build/cli/index.js:173:3)
Did you try recovering your dependencies?
Yes
Which terms did you search for in User Guide?
https://create-react-app.dev/docs/troubleshooting/
Environment
node (via nvm): 14.15.4
npm (via nvm): 6.14.10
create-react-app: 5.0.0
Steps to reproduce
(Write your steps here:)
npx create-react-app my-app --template typescript
cd my-app
npm test
Expected behavior
Tests should be executed
Actual behavior
An error is thrown before the watcher is set up and tests are ran
Workaround
Running npm i -D --exact jest-watch-typeahead@0.6.5
solves the problem (as suggested here https://github.com/facebook/create-react-app/issues/11043#issuecomment-942472592)
Issue Analytics
- State:
- Created 2 years ago
- Reactions:113
- Comments:17 (1 by maintainers)
Top Results From Across the Web
reactjs - Failed to initialize watch plugin "node_modules/jest ...
In my case with Vite-React and with Create React App, works: You need to install specifically v0.6.5 of jest-watch-typeahead
Read more >[Solved]-Failed to initialize watch plugin "node_modules/jest ...
I ran my tests again and got an error for not importing React in App.test.js , so I simply imported and it worked....
Read more >Common reasons for ads not showing - Google AdMob Help
Use the following guide to understand common reasons why apps show few or no ads. If you're still having issues, use the Can't...
Read more >Writing Your First E2E Test - Cypress Documentation
What passing and failing tests look like. ... Cypress showing the spec list with the newly created spec ... Watch Cypress reload in...
Read more >https://courses.cs.washington.edu/courses/cse331/1...
When you run `create-react-app`, it always creates the project with the latest ... `npm test` Launches the test runner in the interactive watch...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
the comand
work for me! thanks node version: 14.0.0 npm v6.14.4
Okay. So I believe I found out the actual root cause behind the issue. I will explain:
react-scripts
(5.0.0) has a dependency onjest-watch
(1.0.0) (reference https://github.com/facebook/create-react-app/blob/main/packages/react-scripts/package.json#L55)jest-watch
(1.0.0) requires a Node version of^12.22.0 || ^14.17.0 || >=16.0.0
(reference https://github.com/jest-community/jest-watch-typeahead/blob/ba70243cded73d798102d6d6c3f9fd11a344c0d9/package.json#L96)And I tried out using Node
14.17.0
for scaffolding a new app and then running thenpm test
script. It worked fine.TL;DR; The
react-scripts test
command works with the following Node versions:@raix It would be nice to update https://github.com/facebook/create-react-app/blob/main/packages/react-scripts/package.json#L12 to
^14.17.0 || >=16.0.0