Rajeev Varshney
Rajeev Varshney

Reputation: 1095

Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/node-sass/build'

I am trying to run an Angular application. I execute the ng serve command, but it then shows:

Error: Cannot find module 'node-sass'

Upvotes: 71

Views: 248300

Answers (15)

reza.ansarirad
reza.ansarirad

Reputation: 383

sudo chown -R $(whoami):$(id -gn) "/file path"

Upvotes: 0

Ajay Singh Rana
Ajay Singh Rana

Reputation: 11

sudo chown -R root:$(whoami) /usr/local/lib/node_modules/

sudo chmod -R 775 /usr/local/lib/node_modules/

Just put sudo before npm install -g @angular/cli or any command and then that will start installing

Upvotes: 1

Jahangir Shirinov
Jahangir Shirinov

Reputation: 1

right click on node_modules folder select get info give the access permission (read and write)

Upvotes: 0

Mıktad Tahir Durak
Mıktad Tahir Durak

Reputation: 2864

Run these commands on your terminal:

sudo chown -R $USER /usr/local/lib/node_modules/
sudo chown -R $USER /usr/local/bin/
sudo chown -R $USER /usr/local/share/

Upvotes: 13

habib
habib

Reputation: 1594

2023 Working Solution

npm i --unsafe-perm node-sass

if node_modules is owned by root, then do

sudo su //switched to root user
npm i --unsafe-perm node-sass

Reference: https://github.com/sass/node-sass/issues/2824#issuecomment-575960022

Upvotes: 2

user19134877
user19134877

Reputation:

u need to use a "root" user in your shell,

with this command:

sudo su -

then you should enter your password

and then try to install the package, i think it will work with any package that you try to install globally

more info that help me in this website

http://www.dark-hamster.com/programming/how-to-solve-error-message-eacces-permission-denied-in-nodejs-application/

Upvotes: 0

am2505
am2505

Reputation: 2384

Run this command

sudo npm install -g <ModuleName> --unsafe-perm=true --allow-root

Upvotes: 65

Anirban Sanyal
Anirban Sanyal

Reputation: 1720

Solution:

You need to change the ownership of folder node_modules, because you use sudo npm install -g node-sass, so its ownership is set to root.

To change the ownership to the current user as group -

sudo chown -R root:$(whoami) /usr/local/lib/node_modules/

sudo chmod -R 775 /usr/local/lib/node_modules/

And never use sudo for an npm-related query.

Upvotes: 168

azhar
azhar

Reputation: 380

Make sure you are not in the home directory or other places. You need to go back to root.

Use this command

cd ..
cd ~

Your current location should look like:

~$

After this, run the command to create a project.

Upvotes: 0

Santhosh S Kashyap
Santhosh S Kashyap

Reputation: 1068

If you have not added Node.js pakage.json yet, try running node init. If you already have this, npm install node-sass.

If both are present and you are using Ubuntu, try changing the permission of the folder using chmod -R <path to node module>.

Upvotes: 0

Dhruv Singh
Dhruv Singh

Reputation: 2243

Try this: npm install node-sass@version

If you want the latest, then just try npm install node-sass.

If you're getting an access problem then:

  1. Windows: command prompt in administrator mode, and then run the above.

  2. Mac:

     sudo npm install node-sass
    

References

Upvotes: 1

Ankit Gairola
Ankit Gairola

Reputation: 61

This is due to the user's permission. The user from which you are running the command of npm install is probably doesn't have permission. So you are getting errors.

For that user just give the permission for that project folder. In Mac, use the below steps and give read and write permission to the user for that project folder

  • On your Mac, select a disk, folder, or file, and then choose menu FileGet Info.

  • If the information in Sharing & Permissions isn’t visible, click the arrow.

  • If the lock at the bottom right is locked, click it to unlock the Get Info options, and then enter an administrator name and password.

  • Click a user or group in the Name column, and then choose a privilege setting from the pop-up menu.

    • Read & Write: Allows a user to open the item and change it.

    • Read-only: This allows a user to open the item but not change its contents.

    • Write only (Drop Box): Makes a folder into a drop box. Users can copy items to the drop box, but can’t open it. Only the owner of the dropbox can open it.

    • No Access: Blocks all access to the item.

This helped me to solve the problem.

Upvotes: 6

Taimoor Tariq
Taimoor Tariq

Reputation: 505

I was working in Ionic and had this issue, so I solved this by moving one folder back and running this command:

sudo chmod -R 777 project-directory

And after this:

npm install node-sass --save

Upvotes: 35

Mohan Dere
Mohan Dere

Reputation: 4597

This worked for me -

sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules

Upvotes: 16

swati kiran
swati kiran

Reputation: 705

Try this

sudo npm install -g --unsafe-perm node-sass

Or this

sudo npm install -g --unsafe-perm --verbose @angular/cli

Upvotes: 25

Related Questions