码迷,mamicode.com
首页 > 其他好文 > 详细

Npm install failed with “cannot run in wd”

时间:2016-09-12 12:12:07      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

  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.

  解决办法如下:

  1. 执行npm install命令时加上--unsafe-perm选项:
    [sudo] npm install --unsafe-perm
  2. 或者将unsafe-perm选项添加到package.json文件中:
    "config": {
        "unsafe-perm":true
    }
  3. 不要使用preinstall脚本来安装全局模块,你可以单独安装它们然后在非root账户下安装其它模块,就像下面这样:
    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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!