【问题标题】:Am I missing webpack dependency when trying to deploy to Heroku?尝试部署到 Heroku 时是否缺少 webpack 依赖项?
【发布时间】:2017-07-02 15:31:36
【问题描述】:

我正在尝试将我的项目部署到使用 webpack 的 Heroku。我正在关注这个tutorial 如何使用 webpack 部署我的项目。当我执行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"
  }
}

感谢您的帮助。谢谢。

【问题讨论】:

  • 嗨。我按照您的建议解决了 webpack 错误消息。当我推送到 heroku 时,一切似乎都在成功构建,但我得到一个 Cannot GET / 页面。现在,我收到此错误消息:WARNING in app/js/main.js from UglifyJs,我不太确定它是否已全部连接。我从我的 devDependencies 安装了依赖项,但仍然没有成功。目前有什么建议吗?
  • 我建议您发布另一个问题,其中包含有关您现在面临的问题的完整信息。

标签: javascript reactjs heroku webpack


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2010-09-13
    • 1970-01-01
    • 2018-01-17
    • 2019-12-16
    • 2019-06-07
    • 2015-09-17
    • 2021-12-20
    • 1970-01-01
    • 2016-05-22
    相关资源
    最近更新 更多