使用 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>
我愚蠢的错误是,我将主分支推送到 Heroku,而我的更改在另一个分支中!
确保首先将最新分支与主分支合并
> git checkout master
> git merge your-latest-branch
> git push heroku master
就我而言,改变这个:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
对此:
"scripts": {
"start": "node app.js"
},
就是解决方案
出于某种原因,将启动脚本推到顶部解决了问题
所以而不是
"scripts": {
"test": "jest",
"start": "node app.js"
}
我做到了
"scripts": {
"start": "node app.js",
"test": "jest"
}
我的 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再次部署应用程序。
经过多次故障排除后,我在尝试使用 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).
然后您可以继续提交文件。
希望这有帮助
我使用的是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]:启动进程 命令
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 错误!npm start
/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]:启动进程 命令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 此运行的完整日志可以在以下位置找到: ................................等等npm start
我发现 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
一切都很顺利。