无法将nodejs应用程序部署到heroku

时间:2017-03-08 12:21:04

标签: node.js reactjs express heroku

我正在尝试将nodejs应用程序部署到heroku,当我检查heroku logs时,我收到以下错误,

  

sh:1:npm-run-all:not found

我的 package.json 看起来像这样

 {


         "name": "web-training",
          "version": "1.0.0",
          "description": "web-training",
          "scripts": {
            "prestart": "babel-node tools/startMessage.js",
            "start": "npm-run-all --parallel open:src lint:watch test:watch",
            "open:src": "babel-node tools/srcServer.js",
            "lint": "node_modules/.bin/esw webpack.config.* src tools",
            "lint:watch": "npm run lint -- --watch",
            "test": "mocha --reporter spec tools/testSetup.js \"src/**/*.test.js\"",
            "test:watch": "npm run test -- --watch",
            "clean-dist": "npm run remove-dist && mkdirp dist-server/dist",
            "remove-dist": "node_modules/.bin/rimraf ./dist-server/dist",
            "build:html": "babel-node tools/buildHtml.js",
            "prebuild": "npm-run-all clean-dist test lint build:html",
            "build": "babel-node tools/build.js",
            "postbuild": "babel-node dist-server/server.js"
          },
          "author": "Cory House",
          "license": "MIT",
          "dependencies": {
            "babel-polyfill": "6.8.0",
            "bootstrap": "3.3.6",
            "compression": "^1.6.1",
            "express": "^4.13.4",
            "install": "^0.8.4",
            "jquery": "2.2.3",
            "material-ui": "^0.16.7",
            "npm": "^4.0.5",
            "open": "0.0.5",
            "rd-react-overlay": "^1.4.2",
            "react": "15.0.2",
            "react-dom": "15.0.2",
            "react-native-search-bar": "^2.16.0",
            "react-native-vector-icons": "^4.0.0",
            "react-redux": "4.4.5",
            "react-router": "2.4.0",
            "react-router-redux": "4.0.4",
            "react-skylight": "^0.4.1",
            "react-tap-event-plugin": "^2.0.1",
            "redux": "3.5.2",
            "redux-thunk": "2.0.1",
            "toastr": "2.1.2"
          },
          "devDependencies": {
            "axios-mock-adapter": "^1.7.1",
            "babel-cli": "6.8.0",
            "babel-core": "6.8.0",
            "babel-loader": "6.2.4",
            "babel-plugin-react-display-name": "2.0.0",
            "babel-preset-es2015": "6.6.0",
            "babel-preset-react": "6.5.0",
            "babel-preset-react-hmre": "1.1.1",
            "babel-register": "6.8.0",
            "colors": "1.1.2",
            "compression": "1.6.1",
            "cross-env": "1.0.7",
            "css-loader": "0.23.1",
            "enzyme": "2.2.0",
            "eslint": "2.9.0",
            "eslint-plugin-import": "1.6.1",
            "eslint-plugin-react": "5.0.1",
            "eslint-watch": "2.1.11",
            "eventsource-polyfill": "0.9.6",
            "expect": "1.19.0",
            "express": "4.13.4",
            "extract-text-webpack-plugin": "1.0.1",
            "file-loader": "0.8.5",
            "jsdom": "8.5.0",
            "mocha": "2.4.5",
            "nock": "8.0.0",
            "npm-run-all": "1.8.0",
            "open": "0.0.5",
            "react-addons-test-utils": "15.0.2",
            "react-search-component": "^1.1.2",
            "redux-immutable-state-invariant": "1.2.3",
            "redux-mock-store": "1.0.2",
            "rimraf": "2.5.2",
            "style-loader": "0.13.1",
            "url-loader": "0.5.7",
            "webpack": "1.13.0",
            "webpack-dev-middleware": "1.6.1",
            "webpack-hot-middleware": "2.10.0"
          },
          "repository": {
            "type": "git",
            "url": "https://github.com/XXX/YYY"
          }
}

当我在命令行中使用npm run build在本地运行我的应用程序时,它运行正常。 有什么建议吗?

我正在添加Procfile内容:

web:npm run build  

我不确定没问题。

3 个答案:

答案 0 :(得分:2)

您需要将npm-run-all添加到您的“ 依赖项”中,而不是添加到package.json中的“ devDependancies ”中。

这是因为在部署到Heroku时,npm在构建production时会修剪您的“ devDependancies ”。

答案 1 :(得分:1)

我想分享自己的经验,因为我在使用npm-run-all部署到Heroku时遇到了类似的问题。

在构建应用程序时,默认情况下Heroku运行 start 脚本,并且无法成功运行npm-run-all(我在终端中运行heroku logs后发现) 。我最初使用this这样的脚本(请注意我在启动脚本中使用npm-run-all的方式)并遇到应用程序错误。

我只是将开始脚本更改回node server.js并创建了一个新脚本来运行npm-run-all,例如this。这对我有用。

(对图片链接感到抱歉。除非我有至少10个声誉,否则我不会发布图片。)

希望这有助于其他人遇到同样的问题。

答案 2 :(得分:0)

·首先在git和heroku中创建您的帐户

·在你的系统上安装git和heroku ..如果你的使用windows必须安装git bash

·在git中创建存储库

·现在找出下面的命令

  -git init

  -git clone {git repository url}

  -cd {repository folder name}

·将代码复制到本地git存储库文件夹

·打开终端转到您的存储库文件夹然后应用以下命令

  -git init

  -git add *

  -git commit -m "your comment"

  -git status

  -git push origin master

·在git cloud上检查你的git存储库

·在命令下打开新终端

  -git clone {repository url}

  -cd {repository url}

  -heroku login

  -heroku create {name of your application on heroku}

  -git remote(to verify heroku)

  -git push heroku master

  -heroku open

**请按照上述步骤在heroku *中部署代码

您可以使用以下命令为heroku部署制作演示节点js项目

  • 表达{项目名称} --ejs
  • cd {项目名称}
  • npm install
  • npm start