ReactJS编译失败:模块';反应';找不到
我遇到了whit编译时错误:ReactJS编译失败:模块';反应';找不到,reactjs,Reactjs,我遇到了whit编译时错误: Failed to compile. ./node_modules/@restart/context/forwardRef.js Module not found: Can't resolve 'react' in 'C:\IdeaProjects\ai\node_modules\@restart\context' 该应用程序突然停止工作,从上一次工作迭代中删除现有更改没有任何帮助。文件夹“./node_modules/@restart/context”已就位且
Failed to compile.
./node_modules/@restart/context/forwardRef.js
Module not found: Can't resolve 'react' in 'C:\IdeaProjects\ai\node_modules\@restart\context'
该应用程序突然停止工作,从上一次工作迭代中删除现有更改没有任何帮助。文件夹“./node_modules/@restart/context”已就位且不为空。我试图删除package-lock.json并重新安装,删除所有模块并重新安装,错误依然存在
我怎样才能解决这个问题
App.js:
import React from 'react';
import './App.css';
import {Trans, withTranslation} from 'react-i18next'
import {Header} from "./components/Header";
import {C2A} from "./components/C2A";
import {DecorationOptions} from "./components/DecorationOptions";
import {ImagesGallery} from "./components/SwipeGallery";
function App({t}) {
return (
<div id="main">
<Header/>
<div className="text_wrapper">
<p><Trans i18nKey='intro1'/></p>
<p><Trans i18nKey='intro2'/></p>
<C2A/>
</div>
<div id="bg-img1" className="background_image" />
<DecorationOptions/>
<div id="bg-img2" className="background_image"/>
<ImagesGallery/>
<div id="temp_separator">
</div>
</div>
);
}
export default withTranslation('common')(App);
请尝试package.json的依赖项中缺少的内容
考虑将其用作react样板文件。您的package.json缺少react依赖项,只需运行npm install react--save
。基本上没有任何理由或任何东西可以从package.json中删除此依赖项,除了删除它或运行npm remove react
您是否尝试过(大致上)清除node\u模块并重新安装的规范解决方案?您的package.json缺少react
依赖项,只需运行npm安装--save@GiladBar:你说得对,非常感谢!你想写一个答案吗?你知道这种改变是怎么发生的吗?是的,我会:)我用过CRA。我仍然不知道这种移除是怎么发生的。非常感谢你的帮助!
{
"name": "ai",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.3.1",
"i18next": "^17.0.11",
"i18next-browser-languagedetector": "^3.0.3",
"react-bootstrap": "^1.0.0-beta.11",
"react-dom": "^16.9.0",
"react-i18next": "^10.12.2",
"react-image-gallery": "^0.9.1",
"react-scripts": "3.1.1"
},
"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"
]
}
}