gpt4 book ai didi

node.js - 为什么 Heroku 没有检测到我的启动脚本?

转载 作者:太空宇宙 更新时间:2023-11-04 01:45:36 26 4
gpt4 key购买 nike

我在 Heroku 上有一个 Node.js 应用程序。要启动它,我需要执行 index.js。为此,我添加了一个带有 start 脚本的 package.json 文件。

正如我在Heroku Node.js Support中读到的那样:

First, Heroku looks for a Procfile specifying your process types.

If no Procfile is present in the root directory of your app during the build process, your web process will be started by running npm start, a script you can specify in package.json...

当我将 start 脚本定义为 node index.js 并将应用程序部署到 Heroku 时,我在资源选项卡中看不到任何 Dynos。

<小时/>

我的代码:

package.json

{
"name": "node.js app",
"version": "1.4.0",
"description": "A node.js app.",
"main": "index.js",
"repository": {
"type": "git",
"url": "Node.js repository"
},
"author": "Realex78",
"license": "MPL-2.0",
"dependencies": {
"npm package": "^1.0.0"
},
"devDependencies": {
"npm package": "^1.0.0"
},
"scripts": {
"start": "node index.js",
"poststart": "node scripts/poststart.js",
"restart": "node scripts/restart.js"
}
}

最佳答案

确保您没有使用 Procfile,如 Heroku gives it priority通过 package.json!

即即使我已经更新了 package.json 中的启动脚本:

  "scripts": {
"start": "node --harmony server.js"
},

我忘记了我的 Procfile 是这样设置的:

web: node server.js

因此我在 package.json 中的启动脚本被忽略了!修复方法是更新我的 Procfile(在本例中包含 --harmony 参数)。
请注意,我不必等待 24 小时才能成功部署;它立即起作用了。

关于node.js - 为什么 Heroku 没有检测到我的启动脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51603671/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com