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

时间:2018-07-30 23:48:11

标签: node.js heroku package.json

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

我在Heroku Node.js Support中读到:

  

首先,Heroku寻找一个Procfile来指定您的进程类型。

     

如果在构建过程中应用程序的根目录中没有Procfile,则将通过运行npm start(可在package.json中指定的脚本)启动Web进程。

当我将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"
    }
}

2 个答案:

答案 0 :(得分:0)

非常感谢您对我的问题的帮助。现在,此问题已解决(Heroku现在已检测到start脚本)。我唯一要做的就是等待(大约24小时)。我不知道为什么在部署应用程序时它没有检测到脚本。

A screenshot of the Resources tab.

答案 1 :(得分:0)

请确保您没有在package.json上使用Heroku gives it priority作为Procfile文件!

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

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

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

web: node server.js

因此,我在package.json中的启动脚本被忽略了!解决方法是更新我的Procfile(在这种情况下,包括--harmony参数)。
请注意,我不必等待24小时就可以成功部署。它立即起作用。