尝试部署到Heroku时,我是否缺少webpack依赖项?

时间:2017-02-14 11:05:24

标签: javascript reactjs heroku webpack

我正在尝试将我的项目部署到使用webpack的Heroku。我正在关注如何使用webpack部署我的项目tutorial。当我git push heroku master时,我收到此错误:

remote:        > webpack -p
remote:        
remote:        sh: 1: webpack: not found
remote:        
remote:        npm ERR! Linux 3.13.0-105-generic
remote:        npm ERR! argv "/tmp/build_4edddf9818027153c0f2847e8272d33e/.heroku/node/bin/node" "/tmp/build_4edddf9818027153c0f2847e8272d33e/.heroku/node/bin/npm" "install" "--unsafe-perm" "--userconfig" "/tmp/build_4edddf9818027153c0f2847e8272d33e/.npmrc"
remote:        npm ERR! node v6.9.5
remote:        npm ERR! npm  v3.10.10
remote:        npm ERR! file sh
remote:        npm ERR! code ELIFECYCLE
remote:        npm ERR! errno ENOENT
remote:        npm ERR! syscall spawn
remote:        npm ERR! fire-emblem-quiz@1.0.0 postinstall: `webpack -p`
remote:        npm ERR! spawn ENOENT
remote:        npm ERR!
remote:        npm ERR! Failed at the fire-emblem-quiz@1.0.0 postinstall script 'webpack -p'.
remote:        npm ERR! Make sure you have the latest version of node.js and npm installed.
remote:        npm ERR! If you do, this is most likely a problem with the fire-emblem-quiz package,
remote:        npm ERR! not with npm itself.
remote:        npm ERR! Tell the author that this fails on your system:
remote:        npm ERR!     webpack -p
remote:        npm ERR! You can get information on how to open an issue for this project with:
remote:        npm ERR!     npm bugs fire-emblem-quiz
remote:        npm ERR! Or if that isn't available, you can get their info via:
remote:        npm ERR!     npm owner ls fire-emblem-quiz
remote:        npm ERR! There is likely additional logging output above.
remote:        

当我查看错误消息时,它说找不到webpack所以我将它作为依赖项安装在我的项目中。但是,我无法部署我的项目。

这是我的webpack配置文件:

module.exports = {
  entry: [
    './src/index.js'
  ],
  output: {
    path: __dirname,
    filename: 'app/js/main.js'
  },
  module: {
    loaders: [{
      test: /\.jsx?$/,
      loader: 'babel',
      exclude: /node_modules/
    }]
  }
}

这是我的package.json文件:

{
  "name": ,
  "version": "1.0.0",
  "description": ,
  "main": "index.js",
  "scripts": {
    "start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
    "prod": "NODE_ENV=production node server.js",
    "postinstall": "webpack -p"
  },
  "author": ,
  "license": "ISC",
  "devDependencies": {
    "babel-core": "5.8.*",
    "babel-loader": "5.3.*",
    "webpack": "^1.14.0"
  },
  "dependencies": {
    "express": "^4.14.1",
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
  }
}

我感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:0)

Hosting a production React app built with Wepback on Heroku的答案中提出了在package.json的devDependencies中指定webpack时,Heroku缺少webpack依赖性问题的几种方法。 遵循最适合您的方法。