Install ReactJS on Ubuntu 18.04 -- npm permission denied - node.js

I am new to Linux and I am trying to get set-up with nodejs, but I have not been able to figure out why I can't install react. I am following directions that I have seen on the web, but I am wondering why I seem to not have the privileges necessary to install react. It's a personal environment, so I wasn't expecting any issue. Below is what I have run and the final error that the last line gave me.
sudo apt update && sudo apt upgrade
sudo apt install nodejs
sudo npm install npm
node -v
v8.10.0
npm -v
3.5.2
sudo npm install npm#latest -g
npm -v
6.10.0
npm install -g create-react-app
Everything above runs just fine until the last command. Then I get the following error, regardless of working directory.
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! 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/me/.npm/_logs/2019-07-06T19_33_32_971Z-debug.log

Using npx (with npm 5.2+)
If you're using npm 5.2+, you may create a ReactJS app like below:
npx create-react-app my-app
Now your app is in a folder my-app, you can cd into the folder and run npm start.
Using older versions of npm with npm install
You may also install it with a global install with npm, infact for older npm versions (< 5.2) the official documentation for create-react-app links to instructions by Dan Abramov (#co-author of create-react-app):
npm install -g create-react-app
However you may need sudo for a global -g install or work around it
Everything above runs just fine until the last command. Then I get the following error, regardless of working directory.
That's because your last command is a global install (-g).
Unless there is a reason against, you may install it with sudo:
sudo npm install -g create-react-app
To install without sudo, please refer to this question: npm throws error without sudo

I was also having this issue, here is how it was resolved
Make sure you have npm installed or use:
sudo apt install npm
Then
sudo npm -g install create-react-app
To create the app I did not use 'npm' before the command line, instead use this:
create-react-app nameofyourapp
That worked for me.

Related

I am not able to install create react app on my m1 macbook pro

Please help me with this error
I ran the following command on iterm after installing node.js and adding it into the path
npm install -g create-react-app
I get the following error
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/create-react-app
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/create-react-app'
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/amaterasu/.npm/_logs/2022-01-04T08_36_06_018Z-debug.log ```
I ran into this earlier today and here is how I fixed it.
npm uninstall -g create-react-app
npx clear-npx-cache
npx create-react-app my-app
If you are interested on the details regarding this issue, than have a look at this github thread
For the npm packages you want to install globally, mainly you may encounter permission problems. This can usually be solved by adding sudo at the first of the line. So instead of:
create-react-app yourAppName
You can do this:
sudo npx create-react-app yourAppName
Following your root user password.
Also, to add more, there are some reported problems with the node js version and create react app. you can check the version of node installed in your Mac, by this command at your terminal:
node --version
if the installed version of the Node is 17.X, it can be assumed it is related to the problem.
It is always recommended to use the LTS version.
enter link description here
you need to have node version >=14 and npm >=5.6 use the command npx create-react-app myapp.
https://reactjs.org/docs/create-a-new-react-app.html#create-react-app
create one folder for react projects.
open that folder in terminal.(commandline)
And use npx create-react-app yourAppName.
Above error is permission related you dont have permission to create new folder under "/usr/local/lib/node_modules/create-react-app".
If this error still comes use sudo npx create-react-app yourAppName.

Including module installation arguments in package.json

I am using the node serialport library, which needs to be installed using the --unsafe-perm and --build-from-source arguments. I only wants those arguments to be used when installing serialport. If I run the following on the command line it works fine:
sudo npm install serialport#5.0.0 --unsafe-perm --build-from-source
Based on this post, my understanding is that you accomplish that by using the preinstall script, like so:
"preinstall": "sudo npm install serialport#5.0.0 --unsafe-perm --build-from-source"
However, I'm getting the following error when I run that:
npm ERR! Error: EACCES: permission denied, mkdir '/Users/test/node_modules/.staging'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, mkdir '/Users/test/node_modules/.staging'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/Users/test/node_modules/.staging' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
So it's not running as root event though I have sudo specified in the command?
How do I get serialport installed through package.json with those flags?
Okay, this took a while to figure out, but I think I get it now.
It turns out that when you have a package.json file that contains a preinstall or postinstall script that you are executing as root, npm will run this with reduced permissions. You have to include the --unsafe-perms flag to let it execute the script as root. So the long and short is that you need to run
sudo npm i --unsafe-perm
or you can create a .npmrc file with this entry:
unsafe-perm = true
If you go the .npmrc route you don't have to specify --unsafe-perm on the command line.
Of course, all of this is only necessary when you are running npm i as root, which isn't really safe. So if you create a regular user and give them full access to the directly in which you are installing your packages, you don't have to worry about --unsafe-perm.
As for --build-from-source, you don't have to worry about that either because when electron-rebuild realizes that it can't download the appropriate package for your environment, it will build it for you.

NPM unable to install browserify globally

I'm unable to install Browserify (or anything) globally. I'm able to install things non-globally without issue.
background: I'm running CentOS 6.6 on a corporate network behind a proxy. I installed Node.js using "yum" as root.
$ sudo yum -y install nodejs
and npm (which wasn't installed with nodejs for some reason):
$ sudo yum -y install nodejs npm
This installed Node.js and NPM to the directories:
$ which node
/usr/bin/node
$ which npm
/usr/bin/npm
and put the "node_modules" under /usr/lib/node_modules.
Like I said, I'm behind a proxy so I set the "proxy" and "https-proxy" config properties to the correct values.
When I tried to install browserify (as specified on their site)
$ npm install -g browserify
I received an error
...npm ERR! stack Error: EACCES, mkdir '/usr/lib/node_modules/browserify'...
So I "chowned" the /usr/lib/node_modules dir to give me access to mkdirs in node_modules:
$ sudo chown -R $USER /usr/lib/node_modules
The error:
Now when I try to install browserify globally I get a different error:
npm ERR! Error: EACCES, symlink '../lib/node_modules/browserify/bin/cmd.js'
npm ERR! { [Error: EACCES, symlink '../lib/node_modules/browserify/bin/cmd.js']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '../lib/node_modules/browserify/bin/cmd.js' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 2.6.32-431.el6.x86_64
npm ERR! command "node" "/usr/bin/npm" "install" "-g" "browserify"
npm ERR! cwd /usr/lib/node_modules
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.3.6
npm ERR! path ../lib/node_modules/browserify/bin/cmd.js
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '../lib/node_modules/browserify/bin/cmd.js'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /usr/lib/node_modules/npm-debug.log
npm ERR! not ok code 0
Is there anything special that I need to change to allow NPM to create the symlink?
Also, I tried running the install as root but it just sits there until eventually timing out:
...npm ERR! network tunneling socket could not be established, cause=read ECONNRESET...
I recently experienced this issue. Global modules should be installed as root (sudo). Where my process was failing (similar to yours) was the timeout when running this as root. This was due to the fact the NPM was using the "git" protocol. To get the packages to install, I had to run the following to my git config.
git config --global url."https://".insteadOf git://
This solved my problem.
I was finally able to install modules globally using npm.
What I did:
I had to use sudo and set the proxy/https proxy in several places. I followed the advice from this blog: http://wil.boayue.com/blog/2013/06/14/using-npm-behind-a-proxy/.
I set the following variables in ~/.bashrc and exported them:
http_proxy
https_proxy
npm_config_proxy
npm_config_https_proxy
I also added them to env_keep using visudo (so they'd be available to sudo).
I then set the proxy and https-proxy config settings on npm using:
$ npm config set proxy http://<proxy>:<port>
$ npm config set proxy http://<proxy>:<port>
I'm not sure if all of this was necessary but it worked for me. Also, at one point I realized that I had the incorrect proxy and had to change it in several places (so be sure to double check that).

NPM permission error while installing

i am trying to install yeoman on my server but for some reason do i keep getting a permission denied error.
$npm install -g yo
/root/.node/bin/yo -> /root/.node/lib/node_modules/yo/cli.js
> yo#1.3.3 postinstall /root/.node/lib/node_modules/yo
> yodoctor
sh: 1: yodoctor: Permission denied
npm ERR! yo#1.3.3 postinstall: `yodoctor`
npm ERR! Exit status 127
npm ERR!
npm ERR! Failed at the yo#1.3.3 postinstall script.
npm ERR! This is most likely a problem with the yo package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! yodoctor
npm ERR! You can get their info via:
npm ERR! npm owner ls yo
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.13.0-37-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "yo"
npm ERR! cwd /root
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR! not ok code 0
i have tried to reinstall ubuntu (14.04) but nothing works.
I think Shantaru is right, you need to do it with sudo.
Try this
sudo npm uninstall -g yo
sudo npm cache clean
sudo npm install -g yo
I have a similar problem weeks ago and that works.
Edit: If that didn't work, do this before:
npm config set unsafe-perm true
You need to have root permission to install this so try
"sudo npm install -g yo" instead of "npm install -g yo"
I had the same issue and tried running the install using 'sudo npm install -g yo' but it still failed. I couldn't get away from the fact that the error message still said 'sh: 1: yodoctor: Permission denied', indicating a permissions issue. I therefore tried completely changing to the root user using 'sudo su' and THEN running 'npm install -g yo'. This worked for me.
If, like me, when running the install that way you encounter other errors, it could be because you need to upgrade npm first (run 'npm install -g npm' to do that). It could also be because you have yo partially installed from your previous attempts and that's causing issues. Therefore you can try removing it first using 'npm remove -g yo' (still as root user) and then installing it again using 'npm install -g yo'.
Hope this helps someone out there.
To avoid permission errors, install node with nvm.
See the detailed solution here:
npm install g less does not work

NPM won't install any package on Mac. New, clean build. `EACCES` & other errors

I've just rebuild my Mavericks (Mac OS X Version 9.4) machine from scratch. I am the administrator and only user of this machine.
I installed Git via their git-2.0.1-intel-universal-snow-leopard.pkg (http://git-scm.com/downloads) in their default /usr/local/git/bin/git location.
I installed Node via their node-v0.10.30.pkg (http://nodejs.org/download/) in their default /usr/local/bin/node location.
The final step of Node's installer package included a note that they also installed NPM in their default /usr/local/bin/npm location.
My $PATH echoes /usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin (it contains /usr/local/bin).
Running npm install -g bower results in:
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/bower']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/bower',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/bower',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 13.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "bower"
npm ERR! cwd /Users/Home
npm ERR! node -v v0.10.30
npm ERR! npm -v 1.4.21
npm ERR! path /usr/local/lib/node_modules/bower
npm ERR! fstream_path /usr/local/lib/node_modules/bower
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/bower'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Home/npm-debug.log
npm ERR! not ok code 0
Running similar installations (npm install -g yo, npm install -g grunt, npm install -g nvm, npm install -g npm) results in what appears to be the same list of errors.
Several people online suggest forcing the installation via sudo, but several others warn this could cause later issues. The manuals for these packages seem not to mention requirement of sudo, and in some cases, they have advised contacting NPM when this issue arises.
Running npm cache clear does not correct the issue.
Running ls -la in the home (~) directory shows my Mac OS X username as the owner of my .npm directory: drwxr-xr-x 15 admin staff 510 Aug 11 23:53 .npm
Does anyone know what has gone wrong and how to correct this? Thank you.
By the way, I solved this issue by changing the owner of /usr/local to be myself, in order to allow NPM to modules in its default location without further requiring sudo for each package's installation.
sudo chown -R `whoami` /usr/local
EACCES is an error of not having access on doing an operation.
Taken the line: npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/bower' we can see that npm was unable to create a directory in the given location.
The reason is very likely that you are not running the command as super user. In fact, the error log is even suggesting that:
npm ERR! Please try running this command again as root/Administrator.
To run as administrator, you have to prefix those commands with sudo. That is:
sudo npm install -g bower. You will be required to type in a password for security reasons.
to start fresh remove prior node.js and npm installs as well as these :
~/.npmrc
~/.npm
~/tmp
~/.npm-init.js
to install nodejs and npm as yourself NOT root do these commands (linux) :
mkdir ${HOME}/bin
download source from : http://nodejs.org/download/
cd v0.10.30/
./configure --prefix=${HOME}/bin/nodejs
make -j8
make install
which puts it into dir defined by above --prefix
export PATH=${HOME}/bin/nodejs/bin:$PATH
NODE_PATH so node can find dir for modules otherwise
npm install xxx will put newly installed module into dir in curr dir :
export NODE_PATH=${HOME}/bin/nodejs/lib/node_modules
do above AND use syntax : npm install xxxxx -g
always use the -g for global
nodejs install gives you npm as well :
ls -la ${HOME}/bin/nodejs/bin
I'd recommend that you install Node.js using a version manager such as nvm. This way, you kill two birds with one stone:
First, you can manage multiple versions of Node.js on the same machine (which you will want to do sooner or later).
Second, you get around all the access problems you experience when installing Node.js without it. At least that's my experience.
Basically it's as easy as running
$ curl https://raw.githubusercontent.com/creationix/nvm/v0.24.1/install.sh | bash
from the command line.
(SOLUTION ANSWER)
Hi Guys,
I had the same problem on my MacBook Pro 2018. After trie installing any dependency globally (with "-g" or "--global") I did receive an issue "EACCES" error (it's about permissions)
You could simply add "sudo" before your commands what will force it.
For example:
sudo npm install gulp -g
or
sudo npm install browser-sync -g
Enjoy!
It's generally not advised to run sudo unless absolutely necessary.
For issues like this, NPM can solve many issues, and allow multiple node versions to be used, and selected depending upon your use case.
I had a similar issue setting up a new machine, and installing NPM took care of the issue.

Resources