5

I'm using npm link as described here

http://npmjs.org/doc/link.html

Locally everything works perfectly. When I deploy to Heroku I get the error message

Error: Cannot find module '...'

How can I get this working with Heroku?

deltanovember
  • 42,611
  • 64
  • 162
  • 244
  • this might help http://stackoverflow.com/questions/5919629/express-module-not-found-when-installed-with-npm – Dhiraj May 05 '12 at 18:24

2 Answers2

3

I wish there were an elegant solution to this (it would make my life a hell of a lot easier). Your custom package is symlinked into node_modules by npm link, but git doesn't follow symbolic links nowadays. So when you git push to Heroku, there's no way to make your custom packages go along for the ride.

Note, however, that from my experiments, Heroku will honor any node_modules you do push in, instead of trying to install them from the network. It just runs npm install --production, essentially. Perhaps a hard link directly to the development source of your package would do the trick, but I'm not sure whether Git would play nicely with that. Use at your own risk!

EDIT: If you want to know exactly what Heroku does, it's all open source.

The ideal situation would be to get the packages, if they're open source, onto NPM itself. Which is pretty painless and automatic.

Community
  • 1
  • 1
btown
  • 2,273
  • 3
  • 27
  • 38
0

If you are hosting your private module on GitHub (or BitBucket), you can add the git repo as a dependency in your package.json.

"dependencies": {
  // ... all your deps
  "my_private_module": "git+ssh://git@github.com:my-username/my-private-module.git"
}

You will, however, need to grant privileges to Heroku to read your repo (assuming it's private -- which is the crux of the issue). Check out this answer for a detailed set of instructions showing how to do so with Github. This might help for Bitbucket.

I've found that the build time increases when doing this. Worth it for my needs.