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

时间:2019-03-26 17:38:20

标签: heroku webpack module create-react-app

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

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

我认为这与this 有关,但是在安装了该插件之后,仍然出现错误。

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(),

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

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

您绝对需要将它们设为dependencies,而不是devDependencies。将它们移至该部分,使用npm installyarn更新锁定文件,然后提交并再次部署。

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