I have a NodeJS app and am having issues with symlinks in the node_modules/.bin folder after using a CI tool (either Travis or CodeShip).
If I run...
npm install
on a new ubuntu server, or my dev machine, my node_modules/.bin folder looks like this:
lrwxrwxrwx 1 ubuntu ubuntu 19 May 10 14:35 gulp -> ../gulp/bin/gulp.js
lrwxrwxrwx 1 ubuntu ubuntu 25 May 10 14:35 nodemon -> ../nodemon/bin/nodemon.js
lrwxrwxrwx 1 ubuntu ubuntu 32 May 10 14:35 randomstring -> ../randomstring/bin/randomstring
However, if I run the project through TravisCI or CodeShip, the node_modules/.bin folder appears to have had the symlinks flattened with only the bin files remaining:
-rwxrwxr-x 1 ubuntu ubuntu 5384 Jan 31 20:55 gulp
-rwxrwxr-x 1 ubuntu ubuntu 441 Apr 29 20:31 nodemon
-rwxrwxr-x 1 ubuntu ubuntu 896 Feb 10 14:14 randomstring
The issue then is that the npm binaries cannot resolve their own internal dependencies because the bin is not being executed from within the context of its npm module folder (e.g. node_modules/nodemon):
> nodemon app.js
module.js:327
throw err;
^
Error: Cannot find module '../lib/cli'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/ubuntu/rawfiles/node_modules/.bin/nodemon:3:11)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
npm ERR! Linux 3.13.0-74-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "start"
npm ERR! node v4.4.4
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! app@0.0.1 start: `nodemon app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app@0.0.1 start script 'nodemon app.js'.
npm ERR! This is most likely a problem with the app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! nodemon app.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls app
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/ubuntu/rawfiles/npm-debug.log
Therefore after attempting to deploy via TravisCI/CodeShip I have to run...
rm -R node_modules
npm install
to get any npm scripts (e.g. npm start) to run.
Is there a configuration item that I don't know about that would have Travis/CodeShip flatten/ignore symlinks? I've been researching this for some time and haven't located an answer.