【问题标题】:Failed Heroku deploy: sh: 1: ng: not foundHeroku 部署失败:sh:1:ng:未找到
【发布时间】:2019-07-03 10:01:12
【问题描述】:

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"
  }
}

server.js 文件

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

})

【问题讨论】:

  • heroku 构建日志:+ @angular/cli@7.3.1 远程:在 14.433 秒远程中添加了来自 179 个贡献者的 295 个包:/tmp/build_65b96372ee3e3abaf6f27c4e836c1557/node_modules/@angular/cli -> /tmp/ build_65b96372ee3e3abaf6f27c4e836c1557/.heroku/node/lib/node_modules/@angular/cli 远程:npm ERR!路径 /tmp/build_65b96372ee3e3abaf6f27c4e836c1557/node_modules/.staging/@angular/cli-cf0b324f/node_modules/@schematics/angular
  • 你检查过这个吗? stackoverflow.com/questions/37227794/…

标签: node.js heroku angular7


【解决方案1】:

你检查过这里的调试日志/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"

您的应用崩溃了。以下是您可以做的一些事情:

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'));
});

3.) 尝试通过在终端中输入来检查您的 nodenpm 版本:

node --version
npm --version

并更新您的 package.json 文件下指示的 nodenpm 版本:

"engines": {
  "node": "10.15.1",
  "npm": "6.4.1"
}

您的问题的另一个更新:

npm ERR! enoent ENOENT: no such file or directory

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

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

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

3.) 升级node到最新版本,删除node_modules目录和package-lock.json,重新安装包。

4.) 如果 npm 仍然不适合您,请尝试 yarn 包管理器 (Yarn)。

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

希望这会有所帮助!

【讨论】:

  • 无法评论,因为我还是个新手,抱歉。你能添加调试日志,我会看看我能做些什么来提供帮助。 :)
  • heroku 构建日志:+ @angular/cli@7.3.1 远程:在 14.433 秒远程中添加了来自 179 个贡献者的 295 个包:/tmp/build_65b96372ee3e3abaf6f27c4e836c1557/node_modules/@angular/cli -> /tmp/ build_65b96372ee3e3abaf6f27c4e836c1557/.heroku/node/lib/node_modules/@angular/cli 远程:npm ERR!路径 /tmp/build_65b96372ee3e3abaf6f27c4e836c1557/node_modules/.staging/@angular/cli-cf0b324f/node_modules/@schematics/angular 我找不到这个文件在哪里。
  • 这是一个 H10 错误。 "heroku[路由器]: 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"
  • 就我而言,我需要在listen() 之外定义端口。例如:const PORT = process.env.PORT || 3000; 然后app.listen(PORT, cb)
  • 感谢我注意到在引擎选项卡中尝试定义旧版本的节点时,它继续使用 10.15.1,这看起来很奇怪。我注意到当我执行 heroku --version 时,Heroku cli 带有自己的节点版本(11.9.0),我尝试在 package.json 中更改它以匹配。还有另一个构建日志 npm ERR! enoent ENOENT: 没有这样的文件或目录,重命名 '/tmp/build_a71fe5a93776d909b8eafd56852942f0/node_modules/.staging/@angular/cli-cc14dd1a/node_modules/@schematics/angular' -> '/tmp/build_a71fe5a93776d909b8chematic/snode_modules/52942 /angular-d146d3ec'
【解决方案2】:

您可能需要添加 devkit/builder,确保其顺序正确。我以粗体添加了它,因此请确保您要复制粘贴以从开头和结尾删除星号。

"@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",
**"@angular-devkit/build-angular": "^0.13.1",
"@angular/language-service": "~7.0.0",**
"core-js": "^2.5.4",
"json": "^9.0.6",
"rxjs": "~6.3.3",
"zone.js": "~0.8.26"

【讨论】:

  • 我相信它需要用于构建的 devkit(正如您从 angular.json 中看到的那样)我也很确定 heroku 默认情况下不会安装开发依赖项。因此,当它安装所有内容时,它会寻找该模块但找不到它。
【解决方案3】:

将一些 devDependencies 移动到 dependencies(角度 9 示例)

 npm i @angular/cli @angular-devkit/build-angular @angular/compiler-cli typescript --save-prod

或将NPM_CONFIG_PRODUCTION 设置为false

here 是对类似问题的回答

【讨论】:

    【解决方案4】:

    根据我的经验,在 Heroku 中部署在本地运行的应用程序并不总是那么简单。在 StackOverflow 中有几个这样的情况没有明确的解决方案,特别是与“找不到‘库’”有关。对于有类似问题的人(尝试在 Heroku 中部署 AngularJS),我建议先查看以下功能教程:

    【讨论】:

      猜你喜欢
      • 2019-07-14
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      • 2021-10-05
      • 2021-12-15
      • 2014-11-07
      • 1970-01-01
      相关资源
      最近更新 更多