I am not able to install create react app on my m1 macbook pro - node.js

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.

Related

uninstalling broken node packages for react native

I am working on a react native app and I had to install node and expo-cli to start the app but recently I have been having issues with running the app. When I run npm start, I get the error expo: command not found so I install the expo-cli using npm install --global expo-cli I get this error:
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /Users/{usr}/.npm-global/lib/node_modules/expo-cli
npm ERR! dest /Users/{usr}/.npm-global/lib/node_modules/.expo-cli-F3yBqKce
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 501:20 "/Users/{usr}/.npm"
I ran the sudo chown -R 501:20 "/Users/{usr}/.npm command but it still does not work.
So I tried to uninstall node and start all over but the issue still persists. Does anyone know a way to fix these issues? Like is there a way I can reset my packages or something like that?
Thanks in advance!

Install ReactJS on Ubuntu 18.04 -- npm permission denied

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.

Unable to install angular cli with npm errno -4048 package.json

I tried installing angular cli with npm. But I'm getting the below error while executing the command npm install -g #angular/cli.
I am not executing this command as admin, but as a user.
D:\AngularWorkstation>npm install -g #angular/cli
npm WARN sass-loader#6.0.6 requires a peer of node-sass#^4.0.0 but none is installed. You must install peer dependencies yourself.
npm ERR! path **D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json.365294863
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall rename
npm ERR! Error: EPERM: operation not permitted, rename 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json.365294863' -> 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json'
npm ERR! { Error: EPERM: operation not permitted, rename 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json.365294863' -> 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json'
npm ERR! cause:
npm ERR! { Error: EPERM: operation not permitted, rename 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json.365294863' ->** 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json'
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'rename',
npm ERR! path: 'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json.365294863',
npm ERR! dest: 'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json' },
npm ERR! stack: 'Error: EPERM: operation not permitted, rename \'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json.365294863\' -> \'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json\'',
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'rename',
npm ERR! path: 'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json.365294863',
npm ERR! dest: 'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json',
npm ERR! parent: '#angular/cli' }
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! C:\Users\techno\AppData\Roaming\npm-cache\_logs\2018-01-03T09_14_35_602Z-debug.log
*PS : I'm using Windows10 OS. I also tried changing the npm global path to'D:\node_modules' to check if it's due to permission issue. However the output is the same.
node --version : v7.7.2
npm --version : 4.1.2*
I had a similar issue when trying to install Yeoman with npm on Windows 10. The culprit turned out to be the McAfee AV software that was installed on my machine.
McAfee seemed to be scanning the changes that npm was trying to make to a json file and as part of the scanning routine, prevented the rename from occurring. This resulted in a 4048 error being raised by npm similar to the error in your output.
To get around this I:
Uninstalled McAfee and restarted my machine so that it reverted to Microsoft's built-in security software.
Re-ran the npm install command and it worked correctly.
Alternatively, you could change the settings of your AV software to not actively check file changes for the node_modules folder. This would hopefully allow your AV software to stay installed and the npm command to work too.
From your error logs, It seems that there is some permission issue while installing the packages. You can specifically resolve this issue by two ways.
1) If you are trying to install the packages globally then you have to run the npm install <pkg_name> -g command with the administrative user or using sudo npm install <pkg_name> -g command.
To install the npm-packages globally you can follow the steps below:
Run the command prompt as the administrative user.
Run npm install <pkg_name> -g.
2) You should try going to the top-level folder in Windows Explorer, right-click on "get more info" option then go down to the permissions section, give yourself all permissions, and tell it to apply them recursively.
Or simply you can go to specified npm working directory and edit to permission section and allow all the permission to the current user and also change the owner to itself for all the recursive directories as well.
Then boot up Windows again.
Note: If you are installing an npm-package locally, then you should be in your local project directory and can try running sudo npm install <pkg-name> command to install required package. the purpose of using sudo is that it will change your owner permissions so you can make your current user authorized to run npm commands.
I'd recommend you to take a look at https://docs.npmjs.com/getting-started/fixing-npm-permissions
1) uninstall node
2) download latest version of node from [https://nodejs.org/en/][1] .
3) install node js

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.

Cannot change npm global location

looks like i messed up something with npm, and i don't know what should i do.
environments:
- Amazon Linux (EC2)
this is the story:
I installed nodejs with yum: "yum install nodejs npm --enablerepo=epel" on my server few months ago.
and then, i knew that there were node version manager(nvm), so i removed my node.js and install the nvm, and then installed latest node.js
but looks like there were something messed up with nvm settings(recently realized) so i removed nodejs with nvm, and then removed nvm.
then i re-installed node.js with same above with yum command. it looks fine, nodejs worked well, but there was big trouble with npm. i checked the location of global modules with command "npm root -g" as normal user(ec2-user), it prints
npm ERR! Error: EACCES, mkdir '/root/.nvm/versions/node/v5.5.0'
npm ERR! { [Error: EACCES, mkdir '/root/.nvm/versions/node/v5.5.0']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/root/.nvm/versions/node/v5.5.0' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 4.1.13-19.31.amzn1.x86_64
npm ERR! command "node" "/usr/bin/npm" "prefix"
npm ERR! cwd /home/ec2-user/modernator
npm ERR! node -v v0.10.42
npm ERR! npm -v 1.3.6
npm ERR! path /root/.nvm/versions/node/v5.5.0
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/root/.nvm/versions/node/v5.5.0'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ec2-user/modernator/npm-debug.log
npm ERR! not ok code 0
so i logged in to admin, and typed same command "npm root -g", it prints:
/usr/lib/node_modules
looks like something is messed up when i removed nvm. everytime i tried to change npm prefix or just try to get any config from npm as normal user, always fail with same error messages!
but if i try with sudo("sudo npm root -g"), it says "/usr/lib/node_modules".
i spend to solve this problem for days but i still working on. and still i don't know even what should i do. every posts found from google not worked. i removed and installed nodejs plenty of times, but not worked. please god, if someone know how to solve this, please give me a advice.
You don't have access by default to root resources.
When you perform this:
npm root -g
It tries it for root user, i bet you need to change user:
npm $USER -g

Resources