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

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

sh:1:npm-run-all:找不到

我的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在本地运行我的应用程序时,它完美地工作。 有什么build议么?

我正在添加Procfile内容:

 web:npm run build 

我不确定没关系。

·首先让你的帐户在Git和Herku

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

·使你的仓库在git中

·现在找出下面的命令

  -git init -git clone {git repository url} -cd {repository folder name} 

将你的代码复制到本地的git仓库文件夹中

打开terminal去你的资源库文件夹,然后应用下面的命令

  -git init -git add * -git commit -m "your comment" -git status -git push origin master 

·在git云上检查你的git仓库

·打开新的terminal申请下面的命令

  -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中部署您的代码*

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

  • expression{项目名称} –ejs
  • cd {项目名称}
  • npm安装
  • npm开始

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

Heroku似乎在构build应用程序时默认运行启动脚本,并且无法成功运行npm-run-all (在terminal中运行heroku logs后发现)。 我最初有我的脚本是这样的 (注意我是如何在我的启动脚本中使用npm-run-all )并遇到应用程序错误。

我只是简单地将启动脚本更改为node server.js并创build了一个运行npm-run-all的新脚本,就像这样 。 这对我有效。

(对于图片链接抱歉,除非我有至less10个声望,否则不会让我发布图片。)

希望这可以帮助其他人遇到同样的问题。