npm link hubot causes require of package.json dependencies to fail
See original GitHub issueImagine having a checkout of hubot at ~/github/hubot
, and you are making a new hubot at ~/github/examplebot`. If you want to work on hubot’s core, and test it in a running bot, you’d run something like:
cd ~/src/hubot
npm link
cd ~/src/examplebot
npm link hubot
After doing this, bin/hubot
in example fails. If you recently used the new generator, it’d fail at the first external-script:
$ bin/hubot
Hubot> [Sun Oct 26 2014 10:23:19 GMT-0400 (EDT)] ERROR Error loading scripts from npm package - Error: Cannot find module 'hubot-diagnostics'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Robot.loadExternalScripts (/Users/technicalpickles/src/hubot/src/robot.coffee:257:11, <js>:206:27)
at /Users/technicalpickles/github/hubot/bin/hubot:119:11, <js>:123:26
at fs.js:266:14
at Object.oncomplete (fs.js:107:15)
I’ve run into this on and off over the years, but never really understood it. Then, I found this article on NODE_DEBUG: http://www.juliengilli.com/2013/05/26/Using-Node.js-NODE_DEBUG-for-fun-and-profit/
Running bin/hubot NODE_DEBUG=module
gave some insight actually. Snipped line:
Module._load REQUEST hubot-diagnostics parent: /Users/technicalpickles/github/hubot/src/robot.coffee
looking for "hubot-diagnostics" in ["/Users/technicalpickles/github/hubot/src/node_modules","/Users/technicalpickles/github/hubot/node_modules","/Users/technicalpickles/github/node_modules","/Users/technicalpickles/node_modules","/Users/node_modules","/node_modules","/Users/technicalpickles/.node_modules","/Users/technicalpickles/.node_libraries","/opt/boxen/nodenv/versions/v0.10.21/lib/node"]
[Sun Oct 26 2014 10:25:59 GMT-0400 (EDT)] ERROR Error loading scripts from npm package - Error: Cannot find module 'hubot-diagnostics'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Robot.loadExternalScripts (/Users/technicalpickles/github/hubot/src/robot.coffee:257:11, <js>:206:27)
at /Users/technicalpickles/github/hubot/bin/hubot:119:11, <js>:123:26
at fs.js:266:14
at Object.oncomplete (fs.js:107:15)
If you look at the paths being investigated, none of them include examplebot. I found this description of loading node_modules, which says it tries to find a node_module in the current directory, it’s parent, and keep going all the way up to the root. However, under the hood, npm link
uses symlinks, and it looks node gets the real path, rather than the symlinked path, so ~/src/hubot and ~/src/examplebot aren’t in the same hierachy, so won’t ever work.
There are two work around I know of to work with a development hubot:
npm install ~/src/hubot
to install directly from the checkout. Annoying because you have to run it every change, it’s easy to forget, and does take a few seconds every timegit clone
hubot into node_modules. You get to see your changes immediately, but it’s risky because it’d be easy to accidentally throw away changes (if package.json of examplebot doesn’t match hubot’s version, it’d reinstall).
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
I just ran into this issue while working on a local copy of Hubot and a script.
I resolved it by adding the following line to
bin/hubot
of my personal bot that is running Hubot:export NODE_PATH=$NODE_PATH:./node_modules
or…
It seems to be working fine.
Actually, the problem with a workaround being in bin/hubot is that is created by generator-hubot so it’s not as easy to update it to get new fixes.