我有一个NodeJS应用程序,在使用CI工具(Travis或CodeShip)后,在node_modules / .bin文件夹中遇到符号链接问题。
如果我跑......
npm install
在新的ubuntu服务器或我的开发机器上,我的node_modules / .bin文件夹如下所示:
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
但是,如果我通过TravisCI或CodeShip运行项目,则node_modules / .bin文件夹似乎已将符号链接展平,只剩下bin文件:
-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
问题是npm二进制文件无法解析它们自己的内部依赖项,因为bin没有在其npm模块文件夹的上下文中执行(例如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
因此,在尝试通过TravisCI / CodeShip部署后,我必须运行...
rm -R node_modules
npm install
运行任何npm脚本(例如npm start)。
是否有一个我不知道的配置项会让Travis / CodeShip变平/忽略符号链接?我已经研究了一段时间了,并找不到答案。
答案 0 :(得分:0)
不幸的是,我还没能找到丢失的符号链接的明确答案。但是我通过添加以下内容解决了手头的问题:
npm install gulp
npm install nodemon
到修复符号链接的BeforeInstall部署挂钩。