安装“ node-sass”后,React应用无法编译。如何修复“找不到模块”错误?

时间:2019-10-14 09:26:43

标签: javascript reactjs npm webpack create-react-app

我已经构建了一个react.js应用,该应用在使用npm install安装“ node-sass”之前运行良好。 使用npm start时,该应用程序可在生产版本中正常运行,但无法在开发版本中编译。 除“ node-sass”以外的任何其他软件包都不会发生此问题

当我将其导入另一台PC并在其中安装“ node-sass”时,该应用程序运行良好。 我尝试重新安装节点和npm,但无济于事。 我也已在全球范围内卸载了node-sass。

这是我的package.json:

  "name": "my_app_name",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "gh-pages": "^2.1.1",
    "node-sass": "^4.12.0",
    "react": "^16.10.2",
    "react-dom": "^16.10.2",
    "react-scripts": "3.2.0"
  },
  "scripts": {
    "predeploy": "npm run build",
    "deploy": "npm run build && gh-pages -d build",
    "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"
    ]
  }
}

这是我不断收到的错误消息:

Failed to compile.

./node_modules/react-dev-utils/formatWebpackMessages.js
Module not found: Can't resolve 'path\to\app\node_modules\babel-preset-react-app\node_modules\@babel\runtime/helpers/slicedToArray' in 'path\to\app\node_modules\react-dev-utils'

1 个答案:

答案 0 :(得分:0)

全局安装node-sass而不是将其打包。 npm i node-sass