为什么我在将应用程序部署到 Heroku 时会出现此错误?

问题描述 投票:0回答:7

使用 git hub 将我的应用程序部署到 heroku 时遇到某种错误。问题是,我不理解 heroku 日志和随之而来的错误。这是 Heroku 日志:

Marcuss-MacBook-Pro:Weather-App marcushurney$ heroku logs
2016-01-05T14:37:27.798077+00:00 app[web.1]: npm ERR! Please include the following file with any support request:
2016-01-05T14:37:27.798377+00:00 app[web.1]: npm ERR!     /app/npm-debug.log
2016-01-05T14:37:27.786949+00:00 app[web.1]: npm ERR! node v5.1.1
2016-01-05T14:37:27.786556+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-01-05T14:37:27.787856+00:00 app[web.1]: npm ERR! npm  v3.3.12
2016-01-05T14:37:28.776245+00:00 heroku[web.1]: Process exited with status 1
2016-01-05T14:37:28.789412+00:00 heroku[web.1]: State changed from starting to crashed
2016-01-05T17:27:16.684869+00:00 heroku[web.1]: State changed from crashed to starting
2016-01-05T17:27:17.853743+00:00 heroku[web.1]: Starting process with command `npm start`
2016-01-05T17:27:20.423495+00:00 app[web.1]: npm ERR! node v5.1.1
2016-01-05T17:27:20.423130+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-01-05T17:27:20.424111+00:00 app[web.1]: npm ERR! npm  v3.3.12
2016-01-05T17:27:20.425937+00:00 app[web.1]: npm ERR! missing script: start
2016-01-05T17:27:20.422441+00:00 app[web.1]: npm ERR! Linux 3.13.0-71-generic
2016-01-05T17:27:20.426242+00:00 app[web.1]: npm ERR! 
2016-01-05T17:27:20.426432+00:00 app[web.1]: npm ERR! If you need help, you may report this error at:
2016-01-05T17:27:20.426634+00:00 app[web.1]: npm ERR!     <https://github.com/npm/npm/issues>
git heroku npm npm-scripts npm-start
7个回答
81
投票

你必须告诉heroku从哪里开始:

missing script: start
。在你的 package.json 中,你应该有类似 this:

的内容
"scripts": {
  "start": "node index.js"
}

其中

index.js
是您的入口点。

作为替代方案,您可以在

Procfile
中指定:

web: node index.js

如何同时使用

如果您仍然想使用 Procfile 中的启动脚本:

web: npm start

在这种情况下,您仍然可以使用您的启动脚本 package.json 文件,因为这是通常的处理方式,Heroku 会考虑它。


6
投票

我愚蠢的错误是,我将主分支推送到 Heroku,而我的更改在另一个分支中!

确保首先将最新分支与主分支合并

> git checkout master

> git merge your-latest-branch

> git push heroku master

4
投票

就我而言,改变这个:

"scripts": {
     "test": "echo \"Error: no test specified\" && exit 1"
    },

对此:

"scripts": {
   "start": "node app.js"
    },

就是解决方案


3
投票

出于某种原因,将启动脚本推到顶部解决了问题

所以而不是

"scripts": {
    "test": "jest",
    "start": "node app.js"
}

我做到了

"scripts": {
    "start": "node app.js",
    "test": "jest"

}

2
投票

我的 Node js 应用程序在将其发布到 heroku.com 时也遇到了类似的错误

首先创建一个procfile,procfile是一个简单的文本文件,但没有任何扩展名。

现在只在 procfile 中放置一行。

web: npm start

现在使用命令创建 package.json 文件

npm init

创建 package.json 文件后,请将 start 属性放入脚本中。

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

现在提交所有 (procfile/package.json) 待处理文件。并从heroku再次部署应用程序。


0
投票

经过多次故障排除后,我在尝试使用 Heroku 部署服务器时遇到了同样的问题。我对 package.json 所做的更改包括在脚本中创建启动属性;

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

进行更改后,确保您的不带扩展名的 Procfile 中有这一行;

  web: node app.js (Depends on your server file).

然后您可以继续提交文件。

希望这有帮助


0
投票

我使用的是nodemon.js,因此我将其包含在package.json中,如下所示: “脚本”

 "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "dev": "nodemon index.js",
     },

但是我收到了 Heroku 错误:

2022-01-06T11:51:55.044364+00:00 heroku[web.1]:启动进程 命令

npm start
2022-01-06T11:51:57.390306+00:00 应用程序[web.1]: npm 呃!缺少脚本:开始 2022-01-06T11:51:57.398106+00:00 应用程序[web.1]:2022-01-06T11:51:57.398334 + 00:00应用程序[web.1]:npm错误! A 此运行的完整日志可以在以下位置找到: 2022-01-06T11:51:57.398402+00:00 应用程序[web.1]:npm 错误!
/app/.npm/_logs/2022-01-06T11_51_57_391Z-debug.log 2022-01-06T11:51:57.598054+00:00 heroku[web.1]:进程退出 状态 1 2022-01-06T11:51:57.882212+00:00 heroku[web.1]:状态已更改 从启动到崩溃 2022-01-06T11:51:57.953568+00:00 heroku[web.1]:状态从崩溃变为启动 2022-01-06T11:52:00.240909+00:00 heroku[web.1]:启动进程 命令
npm start
2022-01-06T11:52:02.010859+00:00 应用程序[web.1]: npm 呃!缺少脚本:开始 2022-01-06T11:52:02.014370+00:00 应用程序[web.1]:2022-01-06T11:52:02.014567 + 00:00应用程序[web.1]:npm错误! A 此运行的完整日志可以在以下位置找到: ................................等等

我发现 Heroku 使用“npm start”来运行我们的应用程序,同时我没有将其包含在 package.json 中;所以将其包含如下:

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

然后重新启动 git 进程:

-heroku restart
-heroku git:remote -a app_name
-git add .
-git commit -am "Your commit"
-git push heroku master

一切都很顺利。

© www.soinside.com 2019 - 2024. All rights reserved.