How to fix permission error while installing Parcel Bundler with terminal - node.js

while installing parcel module in nodeJS, via terminal on Mac OS i am getting permission error.
error: checkPermission Missing write access to /usr/local/lib/node_modules
i am new at learning Node Modules. i tried installing(Node , NPM) everything works perfect. but first time installing node module it throwing error. i know its looking for directory of Windows type URL but i don't know how to fix it for mac.
iMac:~ hassan$ node -v
v11.10.0
iMac:~ hassan$ npm -v
6.7.0
iMac:~ hassan$ npm install -g parcel-bundler
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:
npm ERR! "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! 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/hassan/.npm/_logs/2019-04-23T13_13_46_848Z-debug.log
i want to install Parcel Bundler for Ui animation on my website.

You'll need to have access to /usr/local/lib/node_modules as a super-admin has, to perform the global installation of parcel-bundler.
As mentionned in the comment and assuming your user is the list of sudoers for this computer, you can simply do :
sudo npm -g install parcel-bundler
If this is not the case, you'll need more permissions on the system to install Parcel. Then you'll be able to :
Add your user as a sudoers in the file sudoers.d (Be careful doing this ! See this tutorial for OSX).
Perform the operation directly as the super-admin of the computer.
I'd prefer the 1st option regarding the long-term administration and security of the computer itself. The other option, while not recommended, is still possible for some cases.
Otherwise, you'll not have permission errors if you choose to install Parcel locally. In this case, just omit the -g flag while running the command (i.e npm install parcel-bundler). It will end up by adding parcel to your package.json file so that you'll be able to install it again later.

Related

How to get npm or sass to install globally?

I've been watching tutorials and searching all over, and I've seen several similar issues on here. But none with the same errors. So I apologize if this has been answered before.
I'm taking a self-paced coding class. And I'm supposed to install sass. I finally found a tutorial that seemed straightforward. But when I entered the commands I'm getting error codes in my terminal. I'm very new to all this, so I have no idea what any of this means.
Some context: I downloaded homebrew, but didn't understand that either (so I uninstalled it). So then I Followed THIS tutorial where I downloaded node.js/npm. And everything went fine until I tried the install -g sass command. Then I started getting all these messages and going down the rabbit hole. Npmjs.com has some info on this issue, but I couldn't figure it out. It mentions reinstalling npm, or using "nvm". But when I tried the command npm install -g npm it returned very similar errors.
carlosprieto#Carloss-Mac-mini ~ % npm install -g sass
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/sass
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/sass'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/sass'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/sass'
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/carlosprieto/.npm/_logs/2022-06-17T16_02_28_018Z-debug-0.log
you need admin access, using sudo should help you
sudo npm i -g sass
this means you have superuser access, and is required to install packages globally.
read more here: https://www.tutorialspoint.com/unix_commands/sudo.htm

Gulp installation permission issue

I want to install Gulp 4.0.2 on Mac but it fails due to missing write access.
$ npm i -S gulp -g
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:
npm ERR! '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! 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).
Seems Gulp installation requires root privileges but it is not recommended. I don't want to install gulp as administrator :(
Is it possible to create another user w/o root privileges and install Gulp from there? If yes, how to do that?
Any advice will be appreciated, thanks!
You can install gulp local to your project directory rather than globally:
npm install gulp
You can then run the local version using npx:
npx gulp
Note: npx comes bundled with NPM version 5.2+
You could also use a script in your package.json:
"scripts": {
"gulp": "gulp"
}
npm run gulp
Official docs to avoid these permission issues...
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
Be sure to try touch ~/.zshrc if you're on a newer mac.

Error: EACCES: permission denied, mkdir when installing sth with npm

Everytime I try to install something with npm (in this case electron-packager) I run into this error. How can I solve this issue?
I have already tried to give me access by changing the permissions on .npm via chmod, but it didn't work and I also tried it with another node version (installed via nvm: node -v 12.1.0; npm -v 6.9.0) and it didn`t work as well.
$ npm install electron-packager --save-dev
npm ERR! path /Users/felixmoser/.npm/_cacache/index-v5/15/a0
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'
npm ERR! [OperationalError: EACCES: permission denied, mkdir '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'] {
npm ERR! cause: [Error: EACCES: permission denied, mkdir '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/Users/felixmoser/.npm/_cacache/index-v5/15/a0'
npm ERR! },
npm ERR! isOperational: true,
npm ERR! stack: 'Error: EACCES: permission denied, mkdir ' +
npm ERR! "'/Users/felixmoser/.npm/_cacache/index-v5/15/a0'",
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/Users/felixmoser/.npm/_cacache/index-v5/15/a0',
npm ERR! parent: 'electron-packager'
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 (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/felixmoser/.npm/_logs/2019-05-01T14_11_08_530Z-debug.log
I actually don't know what else I should try now and hope, that you guys can help me solve this problem!
change the ownership of .npm folder,
In my case I couldn't figure out the solution so I used
sudo chown -R $(whoami) ~/.npm
Just change the owner of ~/.npm folder to yourself:
sudo chown -R felixmoser ~/.npm
You'll need to enter your password for calling sudo.
There is also a similar problem with permissions when trying to install packages globally with --global or -g. I know it's not your current problem, but I want to add it here because people googling the EACCESS when doing a global install might reach this question as well.
Some people change the system folder privileges allowing non-root users writing in system folder, however here is what they recommend in the documentation:
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally/
Back up your computer (including it here because documentation mentions is too, but it feels to me overly cautious)
Then execute:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
Edit your ~/.profile:
export PATH=~/.npm-global/bin:$PATH
Then invoke it with
source ~/.profile
To test your new configuration, install a package globally without using sudo:
npm install -g jshint
Or instead of modifying ~/.profile just use the corresponding ENV variable (but to make it pernament you would have to modify the profile file anyway)
NPM_CONFIG_PREFIX=~/.npm-global
Simply add sudo
So instead of npm install electron-packager --save-dev
Let it be sudo npm install electron-packager --save-dev
Please consider running the instructions at least inside the user's location, for example:
/home/myuser/
express HelloWorld --view=pug

Vue-Cli won't install

I have node 11.2.0
Keep receiving this error.
Andrews-MacBook-Pro:vueTutorial aharris$ npm install -g #vue/cli
npm WARN deprecated hoek#5.0.4: This version is no longer maintained. Please upgrade to the latest version.
npm WARN deprecated cross-spawn-async#2.2.5: cross-spawn no longer requires a build toolchain, use it instead
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm WARN #apollographql/apollo-upload-server#5.0.3 requires a peer of graphql#^0.13.1 but none is installed. You must install peer dependencies yourself.
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:
npm ERR! "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! 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/aharris/.npm/_logs/2018-11-25T18_43_42_502Z-debug.log
You are facing the problem of file permissions.
-g parameter of npm means "globally", which will install those file in the system directory, specifically in your computer /usr/local/lib/node_modules, where the owner is possibly root and with permission rwxr-xr-x, means those who is not root will have no permission to write.
Then, you may use sudo to get this permission, or just like NPM modules won't install globally without sudo said, set the npm prefix into the path where you have permissions:
$ npm config set prefix '~/.npm-packages'
All you need to do is run the same command with sudo before it,
sudo npm install -g #vue/cli
and you'll be prompted for the admin password.

error while installing "npm install -g ionic cordova"

When I install npm install -g ionic cordova It throws below error
npm WARN checkPermissions Missing write access to
/usr/lib/node_modules npm ERR! path /usr/lib/node_modules npm ERR!
code EACCES npm ERR! errno -13 npm ERR! syscall access npm ERR! Error:
EACCES: permission denied, access '/usr/lib/node_modules' npm ERR! {
Error: EACCES: permission denied, access '/usr/lib/node_modules' npm
ERR! stack: '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! 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!
/home/javauser/.npm/_logs/2018-05-19T04_42_24_737Z-debug.log
I tried with root user as well.
I am using node v9.11.1 , npm 6.0.1
Never use npm with sudo (or as root)! You can create potential backdoor to your system.
I have just answered a very similar question in the following link: How to fix the problem with vue.js instalation
Basicaly what is happening is that NPM does not have the privileges to access /usr/local/lib. To give it access, you could change the ownership of ~/.npm in order to belong to your current user. This could be this way:
sudo chown -R $(whoami) ~/.npm
This way you do not have to run npm as sudo, which is not recomended. I believe that it is due to vulnerabilities that are known in npm packages.
Here is an article about it: Don't use "sudo" with npm "install"
run with sudo in Mac OS or linux
sudo npm install -g ionic cordova
or in windows open cmd with run as administrator
npm install -g ionic cordova

Resources