question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Failed to initialize watch plugin' when running tests for newly created app

See original GitHub issue

Describe 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:)

  1. npx create-react-app my-app --template typescript
  2. cd my-app
  3. 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:open
  • Created 2 years ago
  • Reactions:113
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

36reactions
yoss5ucommented, Feb 9, 2022

the comand

npm i -D --exact jest-watch-typeahead@0.6.5

work for me! thanks node version: 14.0.0 npm v6.14.4

29reactions
dannyskoogcommented, Mar 26, 2022

Okay. So I believe I found out the actual root cause behind the issue. I will explain:

And I tried out using Node 14.17.0 for scaffolding a new app and then running the npm test script. It worked fine.

TL;DR; The react-scripts test command works with the following Node versions:

  • Major version 14 and minimum minor version 17 (^14.17.0)
  • Major version 16 (>=16.0.0)

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found