32

I have this package.json file:

{
    "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 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!     <npm-@googlegroups.com>
          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.

As anyone succeed deploying a Git dependency on Heroku (works fine on ruby side :P) ?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Julien
  • 9,216
  • 4
  • 37
  • 38

7 Answers7

80

FYI if its on GitHub you can just specify the username/repository and npm will do the rest.

{
    "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.git urls

Fully documented

ndeverge
  • 21,378
  • 4
  • 56
  • 85
Matej
  • 9,548
  • 8
  • 49
  • 66
43

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

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": "https://github.com/juggy/jugglingdb/tarball/master"
    , "nodemailer": "0.2.3"
  }
}
Derek Bredensteiner
  • 2,906
  • 4
  • 23
  • 13
  • Yup that's what I ended up doing, but I think the git link would be better – Julien Nov 29 '11 at 15:57
  • Yes, this worked for me. The syntax is: https://github.com/:organization/:repo/tarball/master – Dan Kohn Jul 16 '13 at 01:52
  • 1
    Worked perfect. I thought I was having proxy issues; but it turned out I was aiming @ the wrong place. – JWally Jul 18 '13 at 11:16
  • 1
    I had to use the url that the above url redirects to https://codeload.github.com/:org/:repo/legacy.tar.gz/master – Jesse Hattabaugh Dec 18 '13 at 23:20
  • I got an error when trying to use this with /master at the end, taking it off works – stackers Nov 15 '16 at 14:25
  • 1
    Tried this now in 2021 and can say adding /tarball/master works still. Thanks! – kennysong Jan 16 '21 at 20:10
  • I changed one lib in `package.json: dependencies { "mux.js": "https://from_github" }`, I can see my code in `node_modules/mux.ts/lib/m2ts/m2ts.js` file. Building a project still use an old code in `dist/video.js` file. No help from `npm install && npm update && npm run build`. Any ideas? – Whome Jul 01 '22 at 13:01
12

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:

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-nodejs and then merging in my chrisleishman/git_fix branch. E.g. (after forking):

git clone git@github.com:@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_URL config variable to your heroku app. E.g.

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.

Chris Leishman
  • 1,777
  • 13
  • 19
  • Nice it is working. Do you know if the dependent packages will be updated if I change the git hash without changing the package.json version? – Julien Jan 10 '12 at 16:52
  • No, they wont be. That's a bug in npm. – Chris Leishman Jan 16 '12 at 16:54
  • 7
    Also, I believe this fix has now been merged into the standard buildpack, so this work-around is no longer required. – Chris Leishman Jan 16 '12 at 16:55
  • 1
    Just a note for anyone who comes across this page trying to reference a GitHub repository, make sure to use the "Git Read-Only" URL in your package.json. If you use one of the private URLs you'll get a different error than the one above, but a similar result. The Read-Only URL works fine. – JBCP May 29 '13 at 15:35
4

Note that you can specify commit-ish to select which commit/branch/... you want to install, in the form "user/foo-project#commit-ish", see doc.

An example:

"dependencies": {
    "express": "visionmedia/express#some-branch",
    "mocha": "visionmedia/mocha#4727d357ea"
}
laike9m
  • 18,344
  • 20
  • 107
  • 140
2

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:

https://devcenter.heroku.com/articles/nodejs-versions

prototype
  • 7,249
  • 15
  • 60
  • 94
1

I had a similar issue except I was referencing a private git repo. My solution for this was to add a postinstall script for the following:

{
    "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)

wlingke
  • 4,699
  • 4
  • 36
  • 52
0

If anyone's struggling with this using npm 5+ (where package-lock.json is a thing), ensure you install the package via command line.

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.json and running npm i will not update package-lock.json (grrr).

rguerrettaz
  • 836
  • 8
  • 12