标签:
Linux环境下,root账户,安装某些npm包的时候报下面的错误,例如安装grunt-contrib-imagemin时:
Error: EACCES, mkdir ‘/usr/local/lib/node_modules/coffee-script‘ npm ERR! { [Error: EACCES, mkdir ‘/usr/local/lib/node_modules/coffee-script‘] npm ERR! errno: 3, npm ERR! code: ‘EACCES‘, npm ERR! path: ‘/usr/local/lib/node_modules/coffee-script‘, npm ERR! fstream_type: ‘Directory‘, npm ERR! fstream_path: ‘/usr/local/lib/node_modules/coffee-script‘, npm ERR! fstream_class: ‘DirWriter‘, npm ERR! fstream_stack: npm ERR! [ ‘DirWriter._create (/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23)‘, npm ERR! ‘/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53‘, npm ERR! ‘Object.oncomplete (fs.js:297:15)‘ ] } npm ERR! npm ERR! Please try running this command again as root/Administrator.
解决办法如下:
[sudo] npm install --unsafe-perm
"config": { "unsafe-perm":true }
sudo npm install -g coffee-script node-gyp npm install
具体内容可以看下面这两个页面的介绍:
https://docs.npmjs.com/misc/scripts#user
https://docs.npmjs.com/getting-started/fixing-npm-permissions
大致意思就是说:如果npm是在root账户下执行的话,它会将uid改成当前账户,或者uid的值从user配置文件中获取,而默认情况下uid的值为nobody。所以在root账户下运行npm install时需要将unsafe-perm选项加上。
Npm install failed with “cannot run in wd”
标签:
原文地址:http://www.cnblogs.com/jaxu/p/5864134.html