LoginSignup
1
0

More than 1 year has passed since last update.

Error: Failed to initialize watch plugin "node_modules/jest-watch-typeahead/filename.js"の対処法【React】

Posted at

エラー内容

  • コマンド
コマンド
npm test
  • 実行例
実行例
>npm test

> react-tmp@0.1.0 test C:\Users\【ユーザ名】\Desktop\ReactTmpApp\react-tmp
> react-scripts test

Error: Failed to initialize watch plugin "node_modules/jest-watch-typeahead/filename.js":

  ● Test suite failed to run

    file:///C:/Users/【ユーザ名】/Desktop/ReactTmpApp/react-tmp/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)

npm ERR! Test failed.  See above for more details.

解決策

以下コマンドを実行する

コマンド
npm i -D --exact jest-watch-typeahead@0.6.5

再実行

以下のようになれば成功

  • コマンド
コマンド
npm test
  • 実行例
実行例
>npm test

> react-tmp@0.1.0 test C:\Users\【ユーザ名】\Desktop\react-test\react-tmp
> react-scripts test
No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press q to quit watch mode.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press Enter to trigger a test run.
 PASS  src/App.test.js
  √ renders learn react link (28 ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        2.068 s
Ran all test suites.

補足

No tests found related to files changed since last commit.
Press `a` to run all tests, or run Jest with `--watchAll`.

Watch Usage
 › Press a to run all tests.
 › Press f to run only failed tests.
 › Press q to quit watch mode.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press Enter to trigger a test run.
  • a : 全てのテストを実行
  • f : 失敗したテストのみ実行
  • o : 変更したファイルのテストのみ実行
  • q : テストを終了する
  • p : 正規表現でファイル名を絞ってテスト実行
  • t : 正規表現でテスト名を絞ってテスト実行
  • Enter : テスト実行
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0