Angular 4 + Express不在Heroku上开始

时间:2017-05-16 19:35:13

标签: json node.js angular heroku

我试图将我的角度4应用程序部署到heroku但我得到的错误就像它找不到“ng命令”等。 我在讨论我需要在package.json中更改某些内容以强制它安装CLI但我无法让它工作。

这是package.json:

{
  "name": "q",
  "version": "0.0.0",
  "license": "MIT",
  "watch": {
    "run-watch": {
      "patterns": [
        "src",
        "server",
        "e2e"
      ],
      "extensions": "js,ts,css,scss,html"
    }
  },
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build && node server/server.js",
    "run-watch": "ng build && node server/server.js",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "watch": "npm-watch"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.1.2",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/material": "^2.0.0-beta.4",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "axios": "^0.16.1",
    "body-parser": "^1.17.1",
    "core-js": "^2.4.1",
    "express": "^4.15.2",
    "hammerjs": "^2.0.8",
    "morgan": "^1.8.1",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/cli": "1.0.3",
    "@angular/compiler-cli": "^4.0.0",
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "node-sass": "^4.5.2",
    "npm-watch": "^0.1.9",
    "protractor": "~5.1.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "~2.2.0"
  }
}

这是我在npm开始时收到的消息:

npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
npm ERR! node v6.10.3
npm ERR! npm  v3.10.10
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
npm ERR! q@0.0.0 start: `ng serve`
npm ERR! spawn ENOENT

如何让cli在服务器上运行?

1 个答案:

答案 0 :(得分:3)

通过将compiler-cli移动到dependecis,添加引擎以获取正确的节点版本并添加post / pre脚本来实现它。

{
  "name": "q",
  "version": "0.0.0",
  "license": "MIT",
  "watch": {
    "run-watch": {
      "patterns": [
        "src",
        "server",
        "e2e"
      ],
      "extensions": "js,ts,css,scss,html"
    }
  },
  "scripts": {
    "ng": "ng",
    "start": "ng build && node server/server.js",
    "build": "ng build && node server/server.js",
    "run-watch": "ng build && node server/server.js",
    "preinstall": "npm install -g @angular/cli",
    "postinstall": "ng build --aot -prod",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "watch": "npm-watch"
  },
  "private": true,
  "dependencies": {
    "@angular/cli": "^1.0.3",
    "@angular/compiler-cli": "^4.0.0",
    "@angular/animations": "^4.1.2",
    "@angular/common": "^4.0.0",
    "@angular/compiler": "^4.0.0",
    "@angular/core": "^4.0.0",
    "@angular/forms": "^4.0.0",
    "@angular/http": "^4.0.0",
    "@angular/material": "^2.0.0-beta.4",
    "@angular/platform-browser": "^4.0.0",
    "@angular/platform-browser-dynamic": "^4.0.0",
    "@angular/router": "^4.0.0",
    "axios": "^0.16.1",
    "body-parser": "^1.17.1",
    "core-js": "^2.4.1",
    "express": "^4.15.2",
    "hammerjs": "^2.0.8",
    "morgan": "^1.8.1",
    "rxjs": "^5.1.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@types/jasmine": "2.5.38",
    "@types/node": "~6.0.60",
    "codelyzer": "~2.0.0",
    "jasmine-core": "~2.5.2",
    "jasmine-spec-reporter": "~3.2.0",
    "karma": "~1.4.1",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^0.2.0",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "node-sass": "^4.5.2",
    "npm-watch": "^0.1.9",
    "protractor": "~5.1.0",
    "ts-node": "~2.0.0",
    "tslint": "~4.5.0",
    "typescript": "~2.2.0"
  }
}