node.js - 使用 Jest 进行纱线测试失败:无法从“Form.js”中找到模块“react”
问题描述
我正在开始我的第一个节点/反应项目,我尝试使用 Jest 编写我的第一个测试。
当我使用它们运行它们时yarn test
,它会失败并显示以下消息:
Cannot find module 'react' from 'Form.js'
However, Jest was able to find:
'./App.css'
'./App.js'
'./App.test.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'].
我使用 create-react-app 创建了我的项目,这是我的 package.json :
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.1",
"shards-react": "^1.0.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:5000"
}
我不明白Form.js
文件是什么,因为我没有创建这样的文件。我想我在 package.json 中的依赖项有问题,但我现在找不到解释。
解决方案
推荐阅读
- javascript - 使用 HtmlMediaElement.captureStream() 从视频中获取音频
- mysql - 如何复制新数据但跳过 MySQL 中 2 个表中的旧数据
- reactjs - React Router DOM - Webpack - 加载资源失败:服务器响应状态为 404(未找到)
- mql4 - 如何删除字符串的某个部分(如果存在)?
- dart - 了解int之间的区别?和 int(或 num?和 num)
- sql - 从包含 $id1,$id2,$id3 的 ids 字段中选择 $id
- ios - 在 NEHotspotConfiguration 中禁用“私人地址”,就像在 iOS Wifi 设置中一样
- javascript - fluent-ffmpeg:如何将许多文件与它们之间的淡入淡出合并
- html - 跟踪几乎相同页面之间的大 CLS 差异
- windows - 在 Windows 上的 Docker 中运行 Qt GUI 应用程序