【发布时间】:2020-06-22 08:57:49
【问题描述】:
在package.json 中运行yarn test 时
CI=true react-app-rewired test --coverage
我收到以下错误
Test suite failed to run
Cannot find module 'react' from 'pure.js'
However, Jest was able to find:
'./pure.js'
You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['web.js', 'js', 'web.ts', 'ts', 'web.tsx', 'tsx', 'json', 'web.jsx', 'jsx', 'node'].
See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string
at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:259:17)
at Object.<anonymous> (../../node_modules/@testing-library/react/dist/pure.js:28:37)
不知道为什么要从pure.js 得到react,知道吗?
【问题讨论】:
-
你是否检查过 React 是否已安装?尝试使用 npm i react 安装并再次运行。如果它有效,那么首先反应没有正确安装。
-
@AJarofClay,我发现该项目有 2 个 package.jsons 顶层目录和内层目录。所以需要坚持内部级别的目录来做开发
标签: reactjs unit-testing jestjs