【发布时间】:2022-07-20 13:33:40
【问题描述】:
希望有人可以在这里帮助我。
在运行 npm test 时出现以下错误
Cannot find module 'react-dom/client' from 'node_modules/@testing-library/react/dist/pure.js'
Required stack:
node_modules/@testing-library/react/dist/pure.js
node_modules/@testing-library/react/dist/index.js
似乎已安装所有必需的软件包。我试图重新安装 react-dom 并没有帮助。下面提供我的测试文件中使用的导入:
import React from "react";
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom';
试图解决这个问题几天...... 提前感谢您的任何帮助
P.S.另外提供我的 package.json
{
"name": "fe",
"version": "0.1.0",
"private": true,
"dependencies": {
"@fontsource/roboto": "^4.5.3",
"@material-ui/core": "^4.12.3",
"@material-ui/icons": "^4.11.2",
"@mui/icons-material": "^5.5.0",
"@mui/material": "5.5.3",
"@mui/styles": "^5.5.1",
"@reduxjs/toolkit": "^1.8.0",
"@testing-library/jest-dom": "5.16.3",
"@testing-library/react": "13.0.0",
"@testing-library/user-event": "14.0.4",
"axios": "^0.26.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-hook-form": "^7.28.1",
"react-redux": "^7.2.6",
"react-router-dom": "^6.2.2",
"react-scripts": "5.0.0",
"redux": "^4.1.2",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.4",
"yup": "^0.32.11"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/jest": "^27.4.0",
"@types/node": "^16.11.25",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"@types/styled-components": "^5.1.24",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"eslint": "^8.9.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.4.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"prettier": "2.5.1",
"typescript": "^4.5.5"
}
}
【问题讨论】:
-
你能分享你的 package.json 文件吗?
-
在上面添加了 package.json
-
Please don't post screenshots of text。它们无法被屏幕阅读器等自适应技术的用户搜索或复制,甚至无法使用。相反,将代码作为文本直接粘贴到您的问题中。如果选择它并单击
{}按钮或Ctrl+K,则代码块将缩进四个空格,这将导致其呈现为代码。
标签: reactjs typescript unit-testing