【问题标题】:Error code ELIFECYCLE when pushing app to Heroku将应用推送到 Heroku 时出现错误代码 ELIFECYCLE
【发布时间】:2022-01-12 14:16:25
【问题描述】:

我正在尝试将我的 Angular 项目应用程序推送到 Heroku,但这样做会收到错误消息。我已经看到有关删除 node_modules 和进行 npm 安装的线程,但是,这对我不起作用。

这是构建日志的样子:

-----> Installing dependencies
       Installing node modules
       
       > nice-napi@1.0.2 install /tmp/build_5dc438c0/node_modules/nice-napi
       > node-gyp-build
       
       
       > esbuild@0.14.2 postinstall /tmp/build_5dc438c0/node_modules/esbuild
       > node install.js
       
       
       > core-js@3.19.3 postinstall /tmp/build_5dc438c0/node_modules/core-js
       > node -e "try{require('./postinstall')}catch(e){}"
       
       
       > @angular/cli@13.1.2 postinstall /tmp/build_5dc438c0/node_modules/@angular/cli
       > node ./bin/postinstall/script.js
       
       added 970 packages in 13.182s
       
-----> Build
       Detected both "build" and "heroku-postbuild" scripts
       Running heroku-postbuild
       
       > project-fatj1700@0.0.0 heroku-postbuild /tmp/build_5dc438c0
       > ng build --prod
       
Node.js version v12.18.2 detected.
The Angular CLI requires a minimum Node.js version of either v12.20, v14.15, or v16.10.
Please update your Node.js version or visit https://nodejs.org/ for additional instructions.
npm ERR! code ELIFECYCLE
npm ERR! errno 3
npm ERR! project-fatj1700@0.0.0 heroku-postbuild: `ng build --prod`
npm ERR! Exit status 3
npm ERR! 
npm ERR! Failed at the project-fatj1700@0.0.0 heroku-postbuild 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!     /tmp/npmcache.RLDGy/_logs/2022-01-12T13_45_01_544Z-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
       
       If you're stuck, please submit a ticket so we can help:
       https://help.heroku.com/
       
       Love,
       Heroku
       
 !     Push rejected, failed to compile Node.js app.
 !     Push failed

我可以做些什么来解决这个错误?

将 "node": "12.20.x" 添加到 "engines" 后:

2022-01-12T14:33:47.000000+00:00 app[api]: Build started by user fabian.tjernstrom@gmail.com
2022-01-12T14:35:25.273203+00:00 app[api]: Deploy 8d86c039 by user fabian.tjernstrom@gmail.com
2022-01-12T14:35:25.273203+00:00 app[api]: Release v4 created by user fabian.tjernstrom@gmail.com
2022-01-12T14:35:26.735671+00:00 heroku[web.1]: State changed from crashed to starting
2022-01-12T14:35:31.764566+00:00 heroku[web.1]: Starting process with command `npm start`
2022-01-12T14:35:33.514980+00:00 app[web.1]:
2022-01-12T14:35:33.514991+00:00 app[web.1]: > project-fatj1700@0.0.0 start /app
2022-01-12T14:35:33.514991+00:00 app[web.1]: > ng serve
2022-01-12T14:35:33.514991+00:00 app[web.1]:
2022-01-12T14:35:33.520075+00:00 app[web.1]: sh: 1: ng: not found
2022-01-12T14:35:33.528901+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2022-01-12T14:35:33.529008+00:00 app[web.1]: npm ERR! syscall spawn
2022-01-12T14:35:33.529086+00:00 app[web.1]: npm ERR! file sh
2022-01-12T14:35:33.529172+00:00 app[web.1]: npm ERR! errno ENOENT
2022-01-12T14:35:33.531393+00:00 app[web.1]: npm ERR! project-fatj1700@0.0.0 start: `ng serve`
2022-01-12T14:35:33.531443+00:00 app[web.1]: npm ERR! spawn ENOENT
2022-01-12T14:35:33.531502+00:00 app[web.1]: npm ERR!
2022-01-12T14:35:33.531554+00:00 app[web.1]: npm ERR! Failed at the project-fatj1700@0.0.0 start script.
2022-01-12T14:35:33.531599+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2022-01-12T14:35:33.536011+00:00 app[web.1]:
2022-01-12T14:35:33.536202+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2022-01-12T14:35:33.536297+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2022-01-12T14_35_33_532Z-debug.log
2022-01-12T14:35:33.669631+00:00 heroku[web.1]: Process exited with status 1
2022-01-12T14:35:33.823240+00:00 heroku[web.1]: State changed from starting to crashed
2022-01-12T14:35:33.842552+00:00 heroku[web.1]: State changed from crashed to starting
2022-01-12T14:35:38.370015+00:00 heroku[web.1]: Starting process with command `npm start`
2022-01-12T14:35:40.529105+00:00 app[web.1]:
2022-01-12T14:35:40.529133+00:00 app[web.1]: > project-fatj1700@0.0.0 start /app
2022-01-12T14:35:40.529133+00:00 app[web.1]: > ng serve
2022-01-12T14:35:40.529133+00:00 app[web.1]:
2022-01-12T14:35:40.532506+00:00 app[web.1]: sh: 1: ng: not found
2022-01-12T14:35:40.536788+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2022-01-12T14:35:40.536888+00:00 app[web.1]: npm ERR! syscall spawn
2022-01-12T14:35:40.536955+00:00 app[web.1]: npm ERR! file sh
2022-01-12T14:35:40.537028+00:00 app[web.1]: npm ERR! errno ENOENT
2022-01-12T14:35:40.539163+00:00 app[web.1]: npm ERR! project-fatj1700@0.0.0 start: `ng serve`
2022-01-12T14:35:40.539208+00:00 app[web.1]: npm ERR! spawn ENOENT
2022-01-12T14:35:40.539258+00:00 app[web.1]: npm ERR!
2022-01-12T14:35:40.539306+00:00 app[web.1]: npm ERR! Failed at the project-fatj1700@0.0.0 start script.
2022-01-12T14:35:40.539355+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2022-01-12T14:35:40.544701+00:00 app[web.1]:
2022-01-12T14:35:40.544777+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2022-01-12T14:35:40.544816+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2022-01-12T14_35_40_539Z-debug.log
2022-01-12T14:35:40.665966+00:00 heroku[web.1]: Process exited with status 1
2022-01-12T14:35:40.748773+00:00 heroku[web.1]: State changed from starting to crashed
2022-01-12T14:35:42.234593+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=miun-project-angular.herokuapp.com request_id=096b472c-7443-40cd-ba7f-b26afa11cc0a fwd="78.67.87.44" dyno=
connect= service= status=503 bytes= protocol=https
2022-01-12T14:35:42.443809+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=miun-project-angular.herokuapp.com request_id=ff6630c8-1a6c-45f3-9d68-ab729c25ccd9 fwd="78.67.87.44" dyno= connect= service= status=503 bytes= protocol=https
2022-01-12T14:35:43.000000+00:00 app[api]: Build succeeded
2022-01-12T14:35:46.092795+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=miun-project-angular.herokuapp.com request_id=34abf454-a40f-48bf-bf92-fd91e9792dea fwd="78.67.87.44" dyno=
connect= service= status=503 bytes= protocol=https
2022-01-12T14:35:46.297579+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=miun-project-angular.herokuapp.com request_id=bb11c150-6a4d-4cf7-b4be-20711731d61d fwd="78.67.87.44" dyno= connect= service= status=503 bytes= protocol=https
2022-01-12T14:35:59.357083+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=miun-project-angular.herokuapp.com request_id=cfd5c527-5b21-4d03-b08a-7e96c98caac1 fwd="78.67.87.44" dyno=
connect= service= status=503 bytes= protocol=https
2022-01-12T14:35:59.570612+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=miun-project-angular.herokuapp.com request_id=7788fb21-3137-41ef-9ad2-3d529f32266f fwd="78.67.87.44" dyno= connect= service= status=503 bytes= protocol=https
2022-01-12T14:38:08.475690+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=miun-project-angular.herokuapp.com request_id=6d3c3250-a75e-440a-925c-db8b58dc1416 fwd="78.67.87.44" dyno=
connect= service= status=503 bytes= protocol=https
2022-01-12T14:38:08.684035+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=miun-project-angular.herokuapp.com request_id=d05edfd2-984f-433c-9c10-47eed273e9a9 fwd="78.67.87.44" dyno= connect= service= status=503 bytes= protocol=https
2022-01-12T14:38:15.011568+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=miun-project-angular.herokuapp.com request_id=c68e2058-114b-4342-8914-1795524319b6 fwd="78.67.87.44" dyno= connect= service= status=503 bytes= protocol=https
2022-01-12T14:38:14.772764+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=miun-project-angular.herokuapp.com request_id=73fde94f-dfee-4e8b-80e8-924cb59755f7 fwd="78.67.87.44" dyno=
connect= service= status=503 bytes= protocol=https
2022-01-12T14:38:17.861635+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=miun-project-angular.herokuapp.com request_id=e1c0e987-e39d-4994-b8f5-f7f38c28e066 fwd="78.67.87.44" dyno=
connect= service= status=503 bytes= protocol=https
2022-01-12T14:38:18.101642+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=miun-project-angular.herokuapp.com request_id=932a731b-a49b-48b2-a56c-b524b5f6aee1 fwd="78.67.87.44" dyno= connect= service= status=503 bytes= protocol=https

【问题讨论】:

  • 日志建议Please update your Node.js version. The Angular CLI requires a minimum Node.js version of either v12.20, v14.15, or v16.10.

标签: javascript node.js angular heroku


【解决方案1】:

看起来错误出在 package.json 中的 Angular 构建脚本中,而不是 Heroku 本身。

Angular CLI 在错误中显示它至少需要 Node.js v12.20,但您当前正在使用 v12.18.2

要强制 Heroku 使用特定版本的 Node,您可以在 package.jsonengines 对象中指定版本。

只需将其添加到您的 package.json 并将应用重新部署到 Heroku。

"engines": {
    "node": "12.20.x"
}

我建议在部署新项目时使用most recent LTS version 以尽可能长时间地保持最新状态。

有关使用自定义构建参数将 Node 应用程序部署到 Heroku 的其他文档,请参见 here

【讨论】:

  • 这也不起作用。我会将错误日志发布到我的 og 帖子中。
  • @FabianTjernström 我对部署 Angular 应用程序并不完全熟悉,但我相信您可能只是在依赖项中缺少 Angular CLI。 Heroku 需要 @angular/cli 包来运行 ng 命令。有关构建和运行应用程序需要哪些 devkit/builder 软件包的参考,请参阅此答案,并确保将它们安装到您的 package.jsondependencies 部分。 stackoverflow.com/a/54893568/6840029
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-27
  • 1970-01-01
  • 1970-01-01
  • 2012-07-22
  • 1970-01-01
  • 2021-11-22
  • 2020-11-15
相关资源
最近更新 更多