为什么我的Heroku构建失败?

时间:2017-12-13 01:29:43

标签: javascript node.js angular typescript heroku

我的heroku构建失败了。我正在尝试在Heroku上构建一个Angular 4应用程序,但它不会让我失望。我有一种感觉它缺少package.json依赖,但我不确定。

-----> Node.js app detected
-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_PRODUCTION=true
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)

       Resolving node version 8.x...
       Downloading and installing node 8.9.3...
       Using default npm version: 5.5.1
-----> Restoring cache
       Skipping cache restore (not-found)
-----> Building dependencies
       Installing node modules (package.json + package-lock)

       > n5-complete-guide@0.0.0 preinstall /tmp/build_245bb93639fea477473780ef82795ada/mgomper-SPA-Front-End-d028559f87c3e58d7bd2c6da70d4ffb0e3e44add
       > npm install -g http-server

       /tmp/build_245bb93639fea477473780ef82795ada/mgomper-SPA-Front-End-d028559f87c3e58d7bd2c6da70d4ffb0e3e44add/.heroku/node/bin/http-server -> /tmp/build_245bb93639fea477473780ef82795ada/mgomper-SPA-Front-End-d028559f87c3e58d7bd2c6da70d4ffb0e3e44add/.heroku/node/lib/node_modules/http-server/bin/http-server
       /tmp/build_245bb93639fea477473780ef82795ada/mgomper-SPA-Front-End-d028559f87c3e58d7bd2c6da70d4ffb0e3e44add/.heroku/node/bin/hs -> /tmp/build_245bb93639fea477473780ef82795ada/mgomper-SPA-Front-End-d028559f87c3e58d7bd2c6da70d4ffb0e3e44add/.heroku/node/lib/node_modules/http-server/bin/http-server
       + http-server@0.10.0
       added 23 packages in 1.212s

       > node@9.2.0 preinstall /tmp/build_245bb93639fea477473780ef82795ada/mgomper-SPA-Front-End-d028559f87c3e58d7bd2c6da70d4ffb0e3e44add/node_modules/node
       > node installArchSpecificPackage

       + node-linux-x64@9.2.0
       added 1 package in 1.676s

       > n5-complete-guide@0.0.0 postinstall /tmp/build_245bb93639fea477473780ef82795ada/mgomper-SPA-Front-End-d028559f87c3e58d7bd2c6da70d4ffb0e3e44add
       > ng build --prod

       sh: 1: ng: not found
       npm ERR! file sh
       npm ERR! code ELIFECYCLE
       npm ERR! errno ENOENT
       npm ERR! syscall spawn
       npm ERR! n5-complete-guide@0.0.0 postinstall: `ng build --prod`
       npm ERR! spawn ENOENT
       npm ERR!
       npm ERR! Failed at the n5-complete-guide@0.0.0 postinstall script.
       npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

       npm ERR! A complete log of this run can be found in:
       npm ERR!     /app/.npm/_logs/2017-12-13T01_22_28_985Z-debug.log
-----> Build failed

       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys

       Some possible problems:

       - Node version not specified in package.json
       https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version

       Love,
       Heroku

 !     Push rejected, failed to compile Node.js app.
 !     Push failed

我不知道为什么会失败,但我真的希望它能够奏效,任何帮助都表示赞赏。如果您需要更多具体细节,请告诉我们!

我的JSON包:

{
  "name": "n5-complete-guide",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "_heroku": "https://www.angularonrails.com/deploy-rails-application-angular-cli-webpack-front-end/",
    "start": "http-server dist/",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor",
    "preinstall": "npm install -g http-server",
    "postinstall": "ng build --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "express": "^4.16.2",
    "ng": "0.0.0-rc6",
    "node": "^9.2.0",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.5.0",
    "@angular/compiler-cli": "^5.0.0",
    "@angular/language-service": "^5.0.0",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.4.2"
  }
}

4 个答案:

答案 0 :(得分:1)

失败,因为没有ng命令可用。它由@angular/cli提供,如果将其移至所需的依赖项并执行本地二进制文件无效,则尝试将您的preinstall脚本更改为:

"preinstall": "npm i -g http-server && npm i -g @angular/cli",

答案 1 :(得分:0)

在postinstall中,您正在使用ng可执行文件,假设它已全局安装。 由于ng也是您的依赖项之一,您可以将其更改为

"postinstall": "./node_modules/.bin/ng build --prod"

答案 2 :(得分:0)

在脚本中使用ng build的部署计算机上未安装@ angular / cli。 这样做

"scripts": {
  ...
  "build:prod": "ng build --prod",
  "heroku-postbuild": "npm run build:prod"
},

注意事项。使用heroku-postbuild代替postinstall。并运行使用本地包(在本例中为ng)的npm脚本。但是在npm脚本中直接运行ng build --prod不会运行。

答案 3 :(得分:0)

  

将@ angular / cli和@ angular / compiler-cli从“devDependencies”移动到“dependencies”。   这是我的package.json:

{
  "name": "mean-app",
  "version": "0.0.0",
  "license": "MIT",
  "engines": {
    "node": "6.11.3",
    "npm": "3.10.10"
  },
  "scripts": {
    "ng": "ng",
    "start": "node server.js",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "heroku-postbuild": "ng build"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/cli": "1.4.9",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "angular2-toaster": "^4.0.1",
    "axios": "^0.17.0",
    "body-parser": "^1.18.2",
    "bootstrap": "^4.0.0-beta.2",
    "core-js": "^2.4.1",
    "cors": "^2.8.4",
    "express": "^4.16.2",
    "jquery": "^3.2.1",
    "mongoose": "^4.12.4",
    "ngx-bootstrap": "^1.9.3",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/language-service": "^4.2.4",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/jquery": "^3.2.15",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.2.0",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "~2.3.3"
  }
}