Reputation: 1095
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
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
Reputation: 1
right click on node_modules folder select get info give the access permission (read and write)
Upvotes: 0
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
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
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
Upvotes: 0
Reputation: 2384
Run this command
sudo npm install -g <ModuleName> --unsafe-perm=true --allow-root
Upvotes: 65
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
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
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
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:
Windows: command prompt in administrator mode, and then run the above.
Mac:
sudo npm install node-sass
Upvotes: 1
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 File → Get 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
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
Reputation: 4597
This worked for me -
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
Upvotes: 16
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