0

我已经使用 Node.js 构建了一个服务器端应用程序。尝试将应用程序部署到 Heroku 时,我通过 Heroku 项目的仪表板在 Heroku 页面上收到“应用程序错误”消息。查看日志时,我看到以下错误:

2021-11-30T10:11:16.238229+00:00 heroku[web.1]: Starting process with command `app.js`
2021-11-30T10:11:16.969594+00:00 app[web.1]: **bash: app.js: command not found**
2021-11-30T10:11:17.091877+00:00 heroku[web.1]: Process exited with status 127
2021-11-30T10:11:17.159203+00:00 heroku[web.1]: State changed from starting to crashed

我已经验证我已经正确安装了npm和node,我在网上找到的所有类似错误都与卸载的node有关,但是错误是“node: command not found”,我得到的错误是不同的。

我的 Procfile 内容:

web: app.js

Procfile 的名称是大写字母,没有扩展名。app.js 文件是我希望应用程序开始的地方。我已将原始 app.js 文件更改为以下内容,以确保它与其内容有关:

console.log('hey!')

在 package.json 里面:

    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1", 
    "start": "node app.js" 
  },

我不确定它是否与 launch.json 文件有关,但它包含以下内容:

        {
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}"
        }
    ]
}

您可以在“url”下看到 localhost 和任意端口号。这可能是我的应用程序无法正常运行的原因之一,但我不确定这是我目前遇到错误的原因(我上面提到的粗体字)。

4

1 回答 1

1

我的 Procfile 内容:

web: app.js

那是你的问题。

如果 aProcfile存在,Heroku 将运行那里给出的命令而不是start脚本中给出的命令。您需要运行node并传递您的脚本名称:

web: node app.js
于 2021-11-30T22:28:15.007 回答