npm run test 报错

来源:5-4 添加Button 测试代码 第一部分

慕沐1385803

2022-05-13

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

● Test suite failed to run

file:///D:/%E7%BB%83%E4%B9%A0/react/my-app/node_modules/jest-watch-typeahead/build/file_name_plugin/prompt.js:4
import { PatternPrompt, printPatternCaret, printRestoredPatternCaret } from 'jest-watcher';
         ^^^^^^^^^^^^^
SyntaxError: The requested module 'jest-watcher' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export.
For example:
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)

老师
react 18.1.0 testing-library/jest-dom 5.16.4
npm run test 报这个错 因为啥

写回答

1回答

张轩

2022-05-14

同学你好

我使用你的代码库 运行 npm test 没有遇到任何的错误, 请看截图:

//img.mukewang.com/szimg/627f0ba40947932f12381054.jpg

我建议你删除 node_modules 然后重装一次应该就可以了

0
2
慕沐1385803
更新了一下node版本 就好了 之前是14+ 更新到了16+
2022-05-16
共2条回复

React18+TS高仿AntD从零到一打造组件库

设计,开发,测试,发布再到 CI/CD,从0到1造轮子

2123 学习 · 959 问题

查看课程