git 推送被拒绝,无法编译 Node.js 应用程序 heroku
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18660474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Push rejected, failed to compile Node.js app heroku
提问by Pixeladed
When I tried to push my nodejs app to heroku with git push heroku master
, i got this:
当我尝试使用 将我的 nodejs 应用程序推送到 heroku 时git push heroku master
,我得到了这个:
Counting objects: 975, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (862/862), done.
Writing objects: 100% (975/975), 3.74 MiB | 80.00 KiB/s, done.
Total 975 (delta 70), reused 0 (delta 0)
-----> Node.js app detected
-----> Resolving engine versions
Using Node.js version: 0.10.15
Using npm version: 1.3.3
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
npm ERR! install Couldn't read dependencies
! Push rejected, failed to compile Node.js app
To [email protected]:hidden-reaches-9268.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:hidden-reaches-9268.git'
And this is my package.json:
这是我的 package.json:
{
"name": "fnBoard",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node server.js"
},
"dependencies": {
"socket.io": "0.9.x"
},
"engines": {
"node": "0.10.x",
"npm": "1.3.x"
}
}
There's a bunch of error inside and I have no idea why this happen. please help. -thanks
里面有一堆错误,我不知道为什么会这样。请帮忙。-谢谢
采纳答案by Dan Kohn
The easiest way to make this work is to add node_modules to your .gitignore. Lots more info here: Fail to deploy node.js application to heroku
完成这项工作的最简单方法是将 node_modules 添加到您的 .gitignore 中。这里有更多信息:无法将 node.js 应用程序部署到 heroku
回答by Yogesh Borad
I am working in ReactJSand I am trying to deploy my project on Herokuserver. At that time I have found same error like this:
我在ReactJS工作,我正在尝试在Heroku服务器上部署我的项目。当时我发现了同样的错误:
Push rejected, failed to compile Node.js app.
推送被拒绝,无法编译 Node.js 应用程序。
Solution is:
解决办法是:
If you use yarn:
如果您使用纱线:
git rm yarn.lock
git push heroku master
git rm yarn.lock
git push heroku master
If you use npm:
如果你使用 npm:
git rm package-lock.json
git push heroku master
git rm package-lock.json
git push heroku master
回答by gitjason
Adding node_modules may be easy but not the correct approach here. Instead do git push -f heroku master
in order to FORCE push your updates telling heroku to overwrite any pre-existing node_modules. This way your git repo is not bogged down with node libs.
添加 node_modules 可能很容易,但在这里不是正确的方法。相反git push -f heroku master
,为了强制推送您的更新,告诉 heroku 覆盖任何预先存在的 node_modules。这样你的 git repo 就不会被节点库所困扰。
回答by schmidgallm
Try setting a heroku-postbuild script to your package.json and make sure to include your engines.
尝试将 heroku-postbuild 脚本设置到您的 package.json 并确保包含您的引擎。
"scripts": {
"heroku-postbuild": "npm run build"
},
"engines": {
"npm": "5.6.0",
"node": "8.10.0"
}
I would try and avoid force pushing anything at all costs whether it be to github or heroku.
我会尽量避免强行推送任何东西,无论是 github 还是 heroku。
回答by tborges
I solved this.
I got the same error:
我解决了这个问题。
我得到了同样的错误:
"Push rejected, failed to compile Node.js app"
“推送被拒绝,无法编译 Node.js 应用程序”
but my log was complaining about this Unknown option:
但我的日志抱怨这个未知选项:
'--target'
I solved this digging out on my package.jsonand I found this line of code below:
我在我的package.json上解决了这个问题,我在下面找到了这行代码:
"postinstall": "ng build --aot --target=production"
I removed the --target=production
.
On my terminal:
I commited again $ git commit -m 'anything here'
then $ git push heroku master
And I fixed it.
我删除了--target=production
.
在我的终端上:
我再次提交$ git commit -m 'anything here'
然后$ git push heroku master
我修复了它。
回答by Rami Salim
I had the same issue , the problem was with git add. I had forgotten to add the node_modules files. I closed the terminal and ran the set of commands given in the Getting started with Heroku and NodeJs[1] again. The application was successfully pushed onto the stack.
我有同样的问题,问题出在 git add 上。我忘了添加 node_modules 文件。我关闭了终端并再次运行了 Heroku 和 NodeJs[1] 入门中给出的一组命令。应用程序已成功推送到堆栈上。