node.js 在 Heroku 上使用带有 npm 和 Node 的 Git 依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8243527/
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
Use Git dependencies with npm and Node on Heroku
提问by Julien
I have this package.json file:
我有这个 package.json 文件:
{
"name": "application-name"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"coffee-script": "1.1.3"
, "express": "2.5.0"
, "less": "1.1.5"
, "jade": "0.17.0"
, "connect-redis": "1.2.0"
, "hiredis": "0.1.13"
, "redis": "0.7.1"
, "bcrypt": "0.4.1"
, "promised-io": "0.3.0"
, "jugglingdb": "git://github.com/juggy/jugglingdb.git#master"
, "nodemailer": "0.2.3"
}
}
and I want to deploy to Heroku. It works fine locally with npm version 1.0.105, but it chokes on Heroku (I updated the npm there to 1.0.105 as well):
我想部署到 Heroku。它在 npm 版本 1.0.105 上运行良好,但它在 Heroku 上卡住了(我也将那里的 npm 更新到了 1.0.105):
-----> Heroku receiving push
-----> Fetching custom build pack... done
-----> Node.js app detected
-----> Fetching Node.js binaries
-----> Vendoring node 0.4.7
-----> Installing dependencies with npm 1.0.105
npm ERR! git checkout master fatal: Not a git repository: '.'
npm ERR! Error: `git "checkout" "master"` failed with 128
npm ERR! at ChildProcess.<anonymous> (/tmp/node-npm-Jb2d/lib/utils/exec.js:49:20)
npm ERR! at ChildProcess.emit (events.js:67:17)
npm ERR! at ChildProcess.onexit (child_process.js:192:12)
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <[email protected]>
npm ERR!
npm ERR! System Linux 2.6.32-316-ec2
npm ERR! command "/tmp/node-node-C3jD/bin/node" "/tmp/node-npm-Jb2d/cli.js" "install"
npm ERR! cwd /tmp/build_2yzg7lk83o5m9
npm ERR! node -v v0.4.7
npm ERR! npm -v 1.0.105
npm ERR! git checkout master fatal: Not a git repository: '.'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /tmp/build_2yzg7lk83o5m9/npm-debug.log
npm not ok
! Failed to install dependencies with npm
! Heroku push rejected, failed to compile Node.js app
Also, I do not seem to find a way to get access to that log file in /tmp.
另外,我似乎没有找到访问 /tmp 中该日志文件的方法。
As anyone succeed deploying a Git dependency on Heroku (works fine on ruby side :P) ?
任何人都成功在 Heroku 上部署 Git 依赖项(在 ruby 方面工作正常:P)?
采纳答案by Chris Leishman
The problem is in their nodejs buildpack. I've sent a pull request to Heroku with a fix, but I have no idea if or when they'll respond. Fortunately, there's a not-very-well documented method for using a custom buildpack, which will allow you to work around the issue. I've forked heroku's nodejs buildpack and fixed the problem - available here:
问题出在他们的 nodejs buildpack 中。我已经向 Heroku 发送了一个修复请求,但我不知道他们是否或何时响应。幸运的是,有一种使用自定义 buildpack 的方法并没有很好地记录在案,它可以让您解决这个问题。我已经分叉了 heroku 的 nodejs buildpack 并解决了这个问题 - 在这里可用:
https://github.com/chrisleishman/heroku-buildpack-nodejs/tree/git_fix
https://github.com/chrisleishman/heroku-buildpack-nodejs/tree/git_fix
To use this, you're best creating your own github fork of https://github.com/heroku/heroku-buildpack-nodejsand then merging in my chrisleishman/git_fixbranch. E.g. (after forking):
要使用它,您最好创建自己的https://github.com/heroku/heroku-buildpack-nodejs的 github 分支,然后合并到我的chrisleishman/git_fix分支中。例如(分叉后):
git clone [email protected]:@YOUR-GITHUB-NAME@/heroku-buildpack-nodejs.git
cd heroku-buildpack-nodejs
git remote add chrisleishman git://github.com/chrisleishman/heroku-buildpack-nodejs.git
git fetch chrisleishman
git merge chrisleishman/git_fix
git push
You can then add the BUILDPACK_URLconfig variable to your heroku app. E.g.
然后,您可以将BUILDPACK_URL配置变量添加到您的 heroku 应用程序中。例如
heroku config:add BUILDPACK_URL="git://github.com/@YOUR-GITHUB-NAME@/heroku-buildpack-nodejs.git
The next push to heroku should then use the custom buildpack, containing the fix.
下一次推送到 heroku 时应该使用包含修复程序的自定义构建包。
回答by Matej
FYI if its on GitHub you can just specify the username/repositoryand npm will do the rest.
仅供参考,如果它在 GitHub 上,您可以指定username/repository并且 npm 将完成其余的工作。
{
"name": "application-name"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"coffee-script": "1.1.3"
, "express": "2.5.0"
, "less": "1.1.5"
, "jade": "0.17.0"
, "connect-redis": "1.2.0"
, "hiredis": "0.1.13"
, "redis": "0.7.1"
, "bcrypt": "0.4.1"
, "promised-io": "0.3.0"
, "jugglingdb": "juggy/jugglingdb"
, "nodemailer": "0.2.3"
}
}
Alternatively
或者
Specify one of (git/git+ssh/git+http/git+https)://user@host/repo.giturls
指定的(一个git/ git+ssh/ git+http/ git+https)://user@host/repo.git网址
Fully documented
完整记录
回答by Derek Bredensteiner
I don't know about this package, but I've got others to work with syntax like the following. On heroku, using a http reference to a tar.gz
我不知道这个包,但我有其他人可以使用如下语法。在 heroku 上,使用对 tar.gz 的 http 引用
package.json:
包.json:
{
"name": "application-name"
, "version": "0.0.1"
, "private": true
, "dependencies": {
"coffee-script": "1.1.3"
, "express": "2.5.0"
, "less": "1.1.5"
, "jade": "0.17.0"
, "connect-redis": "1.2.0"
, "hiredis": "0.1.13"
, "redis": "0.7.1"
, "bcrypt": "0.4.1"
, "promised-io": "0.3.0"
, "jugglingdb": "https://github.com/juggy/jugglingdb/tarball/master"
, "nodemailer": "0.2.3"
}
}
回答by laike9m
Note that you can specify commit-ishto select which commit/branch/... you want to install, in the form "user/foo-project#commit-ish", see doc.
请注意,您可以指定commit-ish以选择要安装的 commit/branch/... 形式"user/foo-project#commit-ish",请参阅doc。
An example:
一个例子:
"dependencies": {
"express": "visionmedia/express#some-branch",
"mocha": "visionmedia/mocha#4727d357ea"
}
回答by prototype
Not sure it's the same issue at this date, but I experienced an error message that was the same, and I found I was able to resolve it by explicitly specifying the version of node and npm per this page:
不确定这是同一天的问题,但我遇到了相同的错误消息,我发现我可以通过在此页面上明确指定 node 和 npm 的版本来解决它:
回答by wlingke
I had a similar issue except I was referencing a private git repo. My solution for this was to add a postinstallscript for the following:
我有一个类似的问题,只是我引用了一个私有的 git 仓库。我对此的解决方案是postinstall为以下内容添加脚本:
{
"postinstall": "npm update && npm install package-name"
}
The update & install makes npm update the private repo to latest. (https://github.com/npm/npm/issues/1727)
更新和安装使 npm 将私有存储库更新为最新。( https://github.com/npm/npm/issues/1727)
回答by rguerrettaz
If anyone's struggling with this using npm 5+ (where package-lock.jsonis a thing), ensure you install the package via command line.
如果有人在使用 npm 5+ 时遇到这个问题(哪里package-lock.json有问题),请确保通过命令行安装该软件包。
npm i my_package --save https://github.com/username/repo/archive/v6.5.2.tar.gz
npm i my_package --save https://github.com/username/repo/archive/v6.5.2.tar.gz
As of NPM 5.0.3 simply adding it to package.jsonand running npm iwill not update package-lock.json(grrr).
从 NPM 5.0.3 开始,简单地将它添加到package.json并运行npm i不会更新package-lock.json(grrr)。

