Permissions Errors sometimes occur when installing Node-sass on MAC OS or Liunx systems

Here’s what might happen:


What will you get after reading it

  1. You will successfully resolve node-sass installation woes (same or similar)
  2. Not only node-Sass, but other modules can solve this problem as well
  3. You’ll get multiple solutions for dealing with this kind of problem
  4. You will learn why these problems occur and how to avoid them

Error analysis

User “root” does not have permission to access the dev dir

The root user does not have permissions.

The solutions to the problem are as follows:

Unsafe-perm add parameter (–unsafe-perm)

When installing Node-sass, use the parameter –unsafe-perm

Such as:

npm install --unsafe-perm node-sass
Copy the code

Resolution:

–unsafe-perm defaults to false for root and true for other options

If set to true, the UID/GID will be switched to false during the run Package script, and the installation will fail under non-root users

Add parameter (–user=root)

When installing Node-sass, use the parameter –user=root

Such as:

npm install --user=root node-sass
Copy the code

This parameter specifies the account (UID) to use when executing the script again. The default is nobody

Solution 4 Modify the permission of an existing node

If you are using a compiled version of Node

So your unzipped directory permissions might look like this

DRWXRWXR -x 7 dev dev 4.0k 3月 24 11:25 node-v8.10.0-linux-x64Copy the code

It could be something like that

Drwxrwxr-x 7 500 500 4.0k 3月 24 11:25 node-v8.10.0-linux-x64 drwxrwxr-x 7 500 500 4.0k 3月 24 11:25 node-v8.10.0-linux-x64Copy the code

Change the node directory permission to root

Chown root: a root node - v8.10.0 - Linux - x64Copy the code

Solution 4 Reinstall the Node (NVM is recommended)

NVM is a node version management tool, you can easily download and install node, and can easily switch node versions

This is directly attached to the NVM address, how to install look documentation

How to Prevent Permissions Errors

 ## create.npm-global directory
 mkdir ~/.npm-global
 # # set
 npm config set prefix '~/.npm-global'
 export PATH=~/.npm-global/bin:$PATH
 source ~/.profile

Copy the code

In one of these ways, the problem can be solved.

reference

  • unsafe-perm
  • fixing-npm-permissions
  • npx