I am trying to run an Angular application. I execute the ng serve
command, but it then shows:
Error: Cannot find module 'node-sass'
I am trying to run an Angular application. I execute the ng serve
command, but it then shows:
Error: Cannot find module 'node-sass'
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.
sudo chown -R root:YOUR_USERNAME /usr/local/lib/node_modules/
Jun 18, 2020 at 4:14
checkPermissions Missing write access to /usr/local/lib/node_modules
but this answer was helpful stackoverflow.com/a/40905762/9277453
Nov 20, 2020 at 21:39
Run this command
sudo npm install -g <ModuleName> --unsafe-perm=true --allow-root
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
Try this
sudo npm install -g --unsafe-perm node-sass
Or this
sudo npm install -g --unsafe-perm --verbose @angular/cli
--unsafe-perm
does work.
This worked for me -
sudo chown -R `whoami` ~/.npm
sudo chown -R `whoami` /usr/local/lib/node_modules
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.
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
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
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/
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>
.
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.
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
npm
commands as root
should be avoided whenever possible.