Heroku:找不到模块 create-react-app

Heroku: module not found create-react-app

我有一个正在使用 create-react-app 构建的项目。当我尝试部署到 Heroku 时,出现以下错误:

./src/index.js
Module not found: Can't resolve 'react-redux' in '/app/src'

我认为这与 有关,但在安装该插件后,我仍然遇到错误。

package.json

{
  "name": "",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.8.5",
    "react-dom": "^16.8.5",
    "react-router-dom": "^5.0.0",
    "react-scripts": "2.1.8"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "case-sensitive-paths-webpack-plugin": "^2.2.0",
    "react-redux": "^6.0.1",
    "redux": "^4.0.1"
  }
}

我的 Webpack 配置包含以下行:

isEnvDevelopment && new CaseSensitivePathsPlugin(),

有什么想法吗?

react-reduxredux 本身列在您的 devDependencies 中,因此当您部署到 Heroku 时它们不包括在内。 devDependencies 用于您在开发中而不是在生产中需要的东西。示例可能是 linter、编辑器插件、实时重新加载工具等。

你肯定需要这些 dependencies,而不是 devDependencies。将它们移动到该部分,使用 npm installyarn 更新您的锁定文件,提交并再次部署。

我不熟悉 case-sensitive-paths-webpack-plugin,但您可能也需要移动它。 (虽然看起来您安装它可能只是为了尝试解决您询问的问题。您也许可以删除它。)