Heroku 部署失败:sh:1:ng:未找到

Ale*_*ilu 6 heroku node.js angular7

Heroku 部署失败。一直在查看其他类似的堆栈溢出帖子并更改 package.json 文件尝试解决方案,这些解决方案对其他人没有运气。我不确定这是端口问题,还是 package.json 问题或完全不同的问题。非常感谢任何帮助、提示或建议!

Heroku logs: 

2019-02-09T08:32:56.609533+00:00 heroku[web.1]: State changed from crashed to starting
2019-02-09T08:33:00.956199+00:00 heroku[web.1]: Starting process with command `npm start`
2019-02-09T08:33:03.430137+00:00 heroku[web.1]: State changed from starting to crashed
2019-02-09T08:33:03.257739+00:00 app[web.1]: 
2019-02-09T08:33:03.257781+00:00 app[web.1]: > the-lottery-genie-mean@0.0.0 start /app
2019-02-09T08:33:03.257783+00:00 app[web.1]: > ng serve
2019-02-09T08:33:03.257784+00:00 app[web.1]: 
2019-02-09T08:33:03.294426+00:00 app[web.1]: sh: 1: ng: not found
2019-02-09T08:33:03.304958+00:00 app[web.1]: npm ERR! file sh
2019-02-09T08:33:03.305986+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-02-09T08:33:03.306367+00:00 app[web.1]: npm ERR! errno ENOENT
2019-02-09T08:33:03.309015+00:00 app[web.1]: npm ERR! syscall spawn
2019-02-09T08:33:03.310700+00:00 app[web.1]: npm ERR! the-lottery-genie-mean@0.0.0 start: `ng serve`
2019-02-09T08:33:03.310912+00:00 app[web.1]: npm ERR! spawn ENOENT
2019-02-09T08:33:03.311266+00:00 app[web.1]: npm ERR! 
2019-02-09T08:33:03.311514+00:00 app[web.1]: npm ERR! Failed at the the-lottery-genie-mean@0.0.0 start script.
2019-02-09T08:33:03.314421+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-02-09T08:33:03.324652+00:00 app[web.1]: 
2019-02-09T08:33:03.324892+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-02-09T08:33:03.325013+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-02-09T08_33_03_316Z-debug.log
2019-02-09T08:33:03.411224+00:00 heroku[web.1]: Process exited with status 1 

package.json: 

{
  "name": "the-lottery-genie-mean",
  "version": "0.0.0",
  "scripts": {
    "preinstall": "npm link @angular/cli ",
    "heroku-postbuild": "ng build --prod",
    "postinstall": "",
    "ng": "ng",
    "start": "node server.js",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/cli": "^7.1.4",
    "@angular/compiler-cli": "~7.0.0",
    "@angular/animations": "~7.0.0",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/forms": "~7.0.0",
    "@angular/http": "~7.0.0",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "core-js": "^2.5.4",
    "json": "^9.0.6",
    "rxjs": "~6.3.3",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.13.1",
    "@angular/language-service": "~7.0.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.1"
  },
  "engines": {
    "node": "10.15.1",
    "npm": "6.4.1"
  }
}
Run Code Online (Sandbox Code Playgroud)

server.js 文件

app.listen(PORT, '0.0.0.0', function () {
console.log("Node app is running at localhost:" + app.get('port'));
Run Code Online (Sandbox Code Playgroud)

})

小智 6

你检查过这里的调试日志吗/app/.npm/_logs/2019-02-09T08_33_03_316Z-debug.log

我建议首先查看调试日志,以获得更多详细信息来解决问题。

更新

Its an H10 error. "heroku[router]: at=error code=H10 desc="App crashed"
method=GET path="/favicon.ico" host=angular-lottery-genie.herokuapp.com
request_id=30e63a79-c395-4d2a-9987-938bcc350629 fwd="50.250.113.70" dyno=
connect= service= status=503 bytes= protocol=https"
Run Code Online (Sandbox Code Playgroud)

您的应用程序崩溃了。您可以执行以下操作:

1.) 重新启动heroku。您应该安装了 heroku CLI。这是链接:Heroku CLI Install。并heroku restart在你的终端上运行。

2.) 使用 Heroku 动态设置的通常可以访问的端口process.env.PORT,并将您所需的端口设置为备份:

app.listen(process.env.PORT || 3000, function(){
  console.log("Node app is running at localhost:" + app.get('port'));
});
Run Code Online (Sandbox Code Playgroud)

3.) 尝试在终端中输入以下内容来检查您的版本nodenpm

node --version
npm --version
Run Code Online (Sandbox Code Playgroud)

并更新package.json 文件下指示的node和版本:npm

"engines": {
  "node": "10.15.1",
  "npm": "6.4.1"
}
Run Code Online (Sandbox Code Playgroud)

您的问题的另一个更新:

npm ERR! enoent ENOENT: no such file or directory
Run Code Online (Sandbox Code Playgroud)

这些错误通常与软件包损坏或不兼容有关。你可以做什么:

1.) 确保后台没有运行其他节点实例,然后重试 npm 命令。

2.) 删除该node_modules目录package-lock.json(如果有)。重新安装在项目目录内的终端中运行的软件包npm install(或用于安装软件包的任何命令)。

3.) 将节点升级到最新版本,删除node_modules目录 和package-lock.json,然后重新安装软件包。

4.) 如果npm仍然不起作用,请尝试yarn包管理器 ( Yarn )。

5.) 如果软件包安装仍然失败,请检查错误日志文件以获取详细的错误报告。

希望这可以帮助!