将nodejs部署到heroku
Posted
技术标签:
【中文标题】将nodejs部署到heroku【英文标题】:deploy nodejs to heroku 【发布时间】:2012-08-10 16:54:09 【问题描述】:我已按照入门指南将 nodejs 应用程序部署到 heroku:https://devcenter.heroku.com/articles/nodejs
在git push heroku master
之前它运行良好。这以以下输出终止:
git push heroku master
Counting objects: 1018, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (894/894), done.
Writing objects: 100% (1018/1018), 4.03 MiB | 64 KiB/s, done.
Total 1018 (delta 75), reused 0 (delta 0)
-----> Heroku receiving push
-----> Node.js app detected
-----> Resolving engine versions
Using Node.js version: 0.6.20
Using npm version: 1.0.106
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
> ws@0.4.21 install /tmp/build_ngyi26sy7e54/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
> node install.js
[ws v0.4.21] Attempting to compile blazing fast native extensions.
[ws v0.4.21] Native code compile failed (but the module will still work):
[ws v0.4.21] The native extensions are faster, but not required.
[ws v0.4.21] On Windows, native extensions require Visual Studio and Python.
[ws v0.4.21] On Unix, native extensions require Python, make and a C++ compiler.
[ws v0.4.21] Start npm with --ws:verbose to show compilation output (if any).
> hiredis@0.1.14 preinstall /tmp/build_ngyi26sy7e54/node_modules/socket.io/node_modules/redis/node_modules/hiredis
> make || gmake
cd deps/hiredis && make static
make[1]: Entering directory `/tmp/build_ngyi26sy7e54/node_modules/socket.io/node_modules/redis/node_modules/hiredis/deps/hiredis'
make[1]: Nothing to be done for `static'.
make[1]: Leaving directory `/tmp/build_ngyi26sy7e54/node_modules/socket.io/node_modules/redis/node_modules/hiredis/deps/hiredis'
node-waf configure build
Setting srcdir to : /tmp/build_ngyi26sy7e54/node_modules/socket.io/node_modules/redis/node_modules/hiredis
Setting blddir to : /tmp/build_ngyi26sy7e54/node_modules/socket.io/node_modules/redis/node_modules/hiredis/build
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /tmp/node-node-Wyfk
'configure' finished successfully (0.029s)
Waf: Entering directory `/home/lhk/Desktop/zwillenhomepage/node_modules/socket.io/node_modules/redis/node_modules/hiredis/build'
Waf: Leaving directory `/home/lhk/Desktop/zwillenhomepage/node_modules/socket.io/node_modules/redis/node_modules/hiredis/build'
Traceback (most recent call last):
File "/tmp/node-node-Wyfk/bin/node-waf", line 16, in <module>
Scripting.prepare(t, os.getcwd(), VERSION, wafdir)
File "/tmp/node-node-Wyfk/bin/../lib/node/wafadmin/Scripting.py", line 145, in prepare
prepare_impl(t, cwd, ver, wafdir)
File "/tmp/node-node-Wyfk/bin/../lib/node/wafadmin/Scripting.py", line 135, in prepare_impl
main()
File "/tmp/node-node-Wyfk/bin/../lib/node/wafadmin/Scripting.py", line 188, in main
fun(ctx)
File "/tmp/node-node-Wyfk/bin/../lib/node/wafadmin/Scripting.py", line 386, in build
return build_impl(bld)
File "/tmp/node-node-Wyfk/bin/../lib/node/wafadmin/Scripting.py", line 405, in build_impl
bld.compile()
File "/tmp/node-node-Wyfk/bin/../lib/node/wafadmin/Build.py", line 268, in compile
os.chdir(self.bldnode.abspath())
OSError: [Errno 2] No such file or directory: '/home/lhk/Desktop/zwillenhomepage/node_modules/socket.io/node_modules/redis/node_modules/hiredis/build'
make: *** [all] Error 1
sh: gmake: not found
npm ERR! hiredis@0.1.14 preinstall: `make || gmake`
npm ERR! `sh "-c" "make || gmake"` failed with 127
npm ERR!
npm ERR! Failed at the hiredis@0.1.14 preinstall script.
npm ERR! This is most likely a problem with the hiredis package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! make || gmake
npm ERR! You can get their info via:
npm ERR! npm owner ls hiredis
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 2.6.32-343-ec2
npm ERR! command "/tmp/node-node-Wyfk/bin/node" "/tmp/node-npm-Rq2Y/cli.js" "rebuild"
npm ERR! cwd /tmp/build_ngyi26sy7e54
npm ERR! node -v v0.6.20
npm ERR! npm -v 1.0.106
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /tmp/build_ngyi26sy7e54/npm-debug.log
npm not ok
! Failed to rebuild dependencies with npm
! Heroku push rejected, failed to compile Node.js app
To git@heroku.com:morning-plateau-9747.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:morning-plateau-9747.git'
我不知道如何解决这个问题。该应用程序仍然是准系统。我决定在 heroku 上启动并运行它,然后逐步添加我想要的功能。它在 localhost 上运行良好,npm 安装所有依赖项都没有错误,并且使用 Procfile 它甚至可以与工头一起使用。我使用 github 创建了 repo 并将其克隆到我的机器上。部署到我的 github 帐户没有问题。这是回购链接https://github.com/lhk/zwillenhomepage
我能做什么?
相关package.json:
"name": "zwillen-webseite",
"scripts":
"start": "server.js"
,
"version": "0.0.1",
"engines":
"node": "0.6.x"
,
"dependencies":
"express": "3.0.x",
"socket.io": "0.9.8",
"jade": "0.27.0"
【问题讨论】:
【参考方案1】:您需要通过将node_modules/hiredis
添加到您的.gitignore
文件中来从源代码管理中删除它。完整答案见socket.io + node.js on heroku
【讨论】:
【参考方案2】:基本上,socket.io 正在使用上下文中的hiredis 模块。
如果您参考 eis 的回答中提到的线程,您会发现你们俩都在使用 socket.io 0.9.8。
尝试使用 0.9.6(我在 heroku 上使用过,从未遇到过此类问题)。
【讨论】:
很奇怪。我对 socket.io 0.9.10 有同样的错误,降级到 0.9.6 修复了它。谢谢!根据github.com/LearnBoost/socket.io/issues/1030,他们在最近的提交中删除了 redis,因此该错误应该很快就会消失。 谢谢你,没有机会了【参考方案3】:基本上它正在尝试编译hiredis并且失败了。这是故意的,你需要吗?您的应用程序中是否引用了hiredis?如果是这样,那可能是罪魁祸首。如果没有,我会尝试联系 Heroku 支持。
另见this thread。
【讨论】:
以上是关于将nodejs部署到heroku的主要内容,如果未能解决你的问题,请参考以下文章
如何将 Typescript、NodeJS 和 Express 应用程序部署到 Heroku
为啥 react+nodejs 应用程序部署到 heroku 显示应用程序错误?
将React + NodeJS + Express + MySQL应用程序部署到Heroku仅部署服务器而不是React