Installation of browser-sync on MAC rejected by OS - node.js

I Just installed node.js on my MAC and then tried to install browser-sync following the web instructions but got these errors but I don't know how to fix it. Could you help me solving it?
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/browser-sync
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/browser-sync'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/browser-sync'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/browser-sync'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.```

As #iLuvLogix said in a comment, it was a matter of giving r/w permissions. After granting permissions I ran into the same problem several times (each time I run the installation command I got a new error on a different folder), so after each try I had to set new permissions until finally I got it installed completely. Annoying but effective.

Related

EACCES error every time I try and do something with npm

Whenever I do anything related to npm, including uninstalling npm itself, I get this error:
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/bin/corepack
npm ERR! dest /usr/local/bin/.corepack-0KY6b4OJ
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/bin/corepack' -> '/usr/local/bin/.corepack-0KY6b4OJ'
npm ERR! [Error: EACCES: permission denied, rename '/usr/local/bin/corepack' -> '/usr/local/bin/.corepack-0KY6b4OJ'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/local/bin/corepack',
npm ERR! dest: '/usr/local/bin/.corepack-0KY6b4OJ'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
This didn't use to be the case as I have had no issues in the past, although the last time I tried to use an npm-related command was about a year ago.
I've tried many solutions, including sudo, nvm and uninstalling Node completely but nothing seems to work. I haven't used Node much before so I'm not very familiar with it unfortunately, so any help would be greatly appreciated.
run npm package as administrator by using the command
sudo npm install -g npm#latest
Turns out it was an issue with my antivirus software! After disabling the software and installing NVM everything now works fine.

Why do I have this terminal issue when I try to install Sass?

I have difficulties in installing Sass.
I am using the Terminal, anyway, when i use npm install -g sass, I am getting error in log file. Here's which answer I receive:
npm WARN checkPermissions Missing write access to /Users/dagilo/desktop/npm-global/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /Users/dagilo/desktop/npm-global/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/Users/dagilo/desktop/npm-global/lib/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/Users/dagilo/desktop/npm-global/lib/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/Users/dagilo/desktop/npm-global/lib/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/admin/.npm/_logs/2021-02-01T14_18_27_655Z-debug.log
iMac-de-admin-3:Dagilo admin$ npm install -g sass
npm WARN checkPermissions Missing write access to /Users/dagilo/desktop/npm-global/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /Users/dagilo/desktop/npm-global/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/Users/dagilo/desktop/npm-global/lib/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/Users/dagilo/desktop/npm-global/lib/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/Users/dagilo/desktop/npm-global/lib/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/admin/.npm/_logs/2021-02-01T14_19_25_392Z-debug.log
Any idea how to solve this?
It's common permission issue in MAC OS so as log suggests you might need to use command sudo npm install -g sass to have privileges this installation requires.
Your log above says:
If you believe this might be a permissions issue, please double-check the permissions of the file and its containing directories, or try running the command again as root/Administrator.
In case you share computer or its company owned, you might need Administrator account or Administrator help to do so.
Additionally here is one relative answer and solution :NPM modules won't install globally without sudo

How to npm install in AWS CloudShell?

I'm trying to install an npm package in the new AWS CloudShell (comes with pre-configured Node.js support) - but I'm getting a EACCESS error.
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! [Error: EACCES: permission denied, access '/usr/lib/node_modules'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/lib/node_modules'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/cloudshell-user/.npm/_logs/2021-01-06T02_18_33_584Z-debug.log
What's the best way to install npm packages in AWS CloudShell?
To get around this problem, I followed the instructions at https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally:
First:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Then:
source ~/.profile

Trying to install Mjml

I am trying to install Mjml email marketing framework on my MAC but I keep receiving this error below
enter code here
MacBook-Air:// desina$ npm init -y && npm install mjml
npm ERR! path /package.json
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied, open '/package.json'
npm ERR! { [Error: EACCES: permission denied, open '/package.json']
npm ERR! stack: 'Error: EACCES: permission denied, open \'/package.json\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: '/package.json' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/desina/.
The issue here is that you're not an administrator on your computer hence the permission-related errors. Ask an administrator to grant you permissions.
An alternative is to run the commands with sudo.
Do you have node js installed and do you have admin privileges for installing? I found the easier method for working in MJML is to install the app, as it comes with the app and language pre-installed.

npm install -g doesn't work for anything

I'm trying to install gatsbyjs using npm using the following command in terminal: npm install -g gatsby-cli. I got a warning and a bunch of errors:
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/simanshrestha/.npm/_logs/2018-07-07T22_48_08_615Z-debug.log
I tried reinstalling Node.js and updating npm using: npm install npm#latest -g but only got a bunch of check permission warnings and the following errors:
npm ERR! path /usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules/npm/node_modules/cacache/node_modules/ssri' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/simanshrestha/.npm/_logs/2018-07-07T22_49_59_092Z-debug.log
I've been trying to fix the permission errors, but am stuck (I'm really new to this stuff).
Edit: I don't want to use sudo as I have seen that it could mess things up from multiple forums.
There are 3 possible solutions to your problem, which is basically lack of root access to install modules to root node_modules dir:
Run sudo npm i -g package#latest. This will fix your problem but will ask for root password every time.
Change your default global modules folder as outlined here with npm config set prefix
Install and use nvm to manage node and npm, it comes out of the box with properly set up folder structure within your local user. So no extra rights needed or messing with config prefixes.
You should run npm install -g as an administrator.
As the console said.

Resources