NPM install failed with "cannot run in WD"

Source: Internet
Author: User

In the Linux environment, the root account, when installing certain NPM packages, reported the following errors, such as when installing 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 the This command again as Root/administrator.

The solution is as follows:

    1. Add the --unsafe-perm option when executing the NPM install command:
      [sudoinstall --unsafe-perm
    2. Or add the unsafe-perm option to the Package.json file:
      "Config": {    "unsafe-perm":true}
    3. Do not use preinstall scripts to install the global modules, you can install them separately and then install other modules under the non-root account, as follows:
      sudo Install -G coffee-scriptnode-Install

The specific content can be seen in the following two pages of the introduction:

Https://docs.npmjs.com/misc/scripts#user

Https://docs.npmjs.com/getting-started/fixing-npm-permissions

The general meaning is: If NPM is executed under the root account, it will change the UID to the current account, or the value of the UID is taken from the user profile, and the UID value is nobody by default. So the unsafe-perm option needs to be added when running npm install under the root account.

NPM install failed with "cannot run in WD"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.