ReactJS编译失败:找不到模块“反应”

时间:2019-09-16 12:46:01

标签: reactjs

我陷入了编译时错误:

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:

{
  "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"
    ]
  }
}

2 个答案:

答案 0 :(得分:2)

您的package.json缺少react依赖项,只需运行npm install react --save。基本上,除了删除它或运行npm remove react

之外,没有任何理由或其他任何方法可以从package.json中删除此依赖项。

答案 1 :(得分:0)

尝试dependencies的{​​{1}}中缺少的concat

考虑使用npm install react作为反应样板。