react-native init AwesomeProject gives an error EPERM: operation not permitted, chmod '/node_modules/#react-native-com...' - macos

After installing brew, watchman and node. I tried to initiate my first react-native application from the terminal on a Mac machine.
When I run the command like it says on React Native Development site - React Native CLI Quickstart for macOS and iOS target.
npx react-native init AwesomeProject
I get the following error
EPERM: operation not permitted, chmod '/usr/local/lib/node_modules/react-native/node_modules/#react-native-community/cli/build/commands/server/external/xsel'
I am logged in as an admin, so that is not an issue, and I have even tried "sudo", but with no success.
Has anybody faced a similar issue?
Thanks in advance.

It seems that you are having a permission problem try to change the permissions to react-native's folder with your username.
sudo chown userName -R [PATH]
to know your username run this command in the terminal
whoami
or just do the following
close all VS Code instances.
clean cache with
npm cache clean --force
install the latest version of npm globally as admin:
npm install -g npm#latest --force
clean cache with
npm cache clean --force
Try to install your component once again.
you may want temporarily disable your antivirus program and try again.

Related

Expo client is not installing on Simulator

I have been using this setup for almost half a year now and I upgraded the Expo SDK to 44 (erased all content and settings on the simulator). Ever since, the expo client won't install on the simulator.
Things I have tried:
run expo client:install:ios
uninstall and reinstall expo
uninstall and reinstall watchman
tried different simulators (15.0 that I used so far)
creating a new blank expo project
open the simulator first and then npm start
I even did a complete MacBook reset (factory, needed to wipe anyway) and reinstalled following the expo documentation.
I read something about installing expo without sudo, but then it will throw errors and will simply not install.
New blank expo project infos:
Expo : 44.0.0
expo-cli: 5.0.3
react-native: 0.64.3
Hope someone knows the solution to this, I really want to get back programming.
I had the same problem. Turns out using sudo when installing expo-cli is the issue. Run the following commands to resolve it.
npm uninstall -g expo-cli
npm install -g expo-cli
Then from your Mac's user's directory in a new terminal, run the following:
mkdir apps
cd apps
expo init app-name
Once this finishes, it should work just fine after running npm start.
As #Mercify said, sudo was indeed the problem.
For future reference: if installing expo without sudo throws an error, it is nessecary to change "the owner" of the folder "/usr/.../node_modules" to your user.
This post helps changing the owner.
Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
Expo is now installing on the Simulator.
Thanks to #Mercify.

Running yarn add requires sudo

For some reason when I try to add packages to a project with yarn add redux-thunk it fails with
error An unexpected error occurred:
"EACCES: permission denied, unlink '/Users/TuzMacbookPro2017/Development/code/ReactJS/recipe-helper-react-js/node_modules/.bin/acorn'".
or some other EACCES error. Adding sudo works, but I shouldn't have to do that in this case, right?
I followed these steps (replacing npm with yarn and now yarn add global works without sudo.
How do I fix the permissions for the normal yarn add command?
Most likely, at some point a package was added using sudo (in this case 'acorn').
Removing everything from node_modules and then reinstalling should fix it:
sudo rm -rf /Users/TuzMacbookPro2017/Development/code/ReactJS/recipe-helper-react-js/node_modules/
yarn install

"exp: command not found" How do I add expo cli to path?

I installed the expo cli with
npm i -g exp
then I run
exp
and I get
-bash: exp: command not found
I'm guessing I didn't add exp to path. So how do I do this properly? Nothing I've tried so far works.
This suggested 3 steps solution worked for me:
First check if ~/.npm-global/bin is in your path: echo $PATH. If it isn’t there, you will need to add it to the path.
Open up ~/.bash_profile then add the following line to the bottom: export PATH=$PATH:~/.npm-global/bin
Finally, back in the shell, type: source ~/.bash_profile
Hopefully that will have fixed your problem.
1. Find the path where expo is globally installed by npm:
npm bin -g
2. Add path from Step 1 to paths file:
sudo vi /etc/paths
3. Restart the Terminal
You should try npx expo init <your_app_name> to test.
It worked for me.
I also had a hard time getting expo command to work on Mac. Here are the steps I took to get it working.
npm root -g shows the directory the global modules are installed in:
/usr/local/Cellar/node/11.7.0/lib/node_modules
That directory might be different for you. After confirming expo is in there, edit ~/.bash_profile and add the line:
export PATH=$PATH:/usr/local/Cellar/node/11.7.0/bin
Save & exit, then run source ~/.bash_profile
Now the expo command should function as intended.
try sudo npm install --global expo-cli
this worked for me.
➜ MobileDev git:(campaigns-responsive) ✗ expo whoami
› Not logged in, run expo login to authenticate
➜ MobileDev git:(campaigns-responsive) ✗ expo init App
✔ Choose a template: › blank a minimal app as clean as an empty canvas
✔ Downloaded and extracted project files.
📦 Using npm to install packages.
✔ Installed JavaScript dependencies.
✅ Your project is ready!
To run your project, navigate to the directory and run one of the following npm commands.
- cd App
- npm start # you can open iOS, Android, or web from here, or run them directly with the commands below.
- npm run android
- npm run ios
- npm run web
exp was replaced with expo
To install Expo CLI, just run npm install -g expo-cli (or yarn global add expo-cli, whichever you prefer).
Following on this issue, I found I had multiple global folders so I started using a .npm-global folder as shown here: https://docs.npmjs.com/getting-started/fixing-npm-permissions
And now it's all clean and in control.
I had a similar issue.
-bash: expo: command not found
It turns out the command to install expo
npm install -g expo-cli was referencing an older version of node on my machine; when checked using npm root -g.
So I had to uninstall nvm/node, deleted any remnant folders & files of .nvm and shortcuts for nvm in /usr/local. Then reinstalled node and ran npm install -g expo-cli again.
That fixed my issue.
sudo npm install --unsafe-perm -g expo-cli
If you're using git bash on windows, add npm path to your system path variables. Generally located on this location:
C:\Users\<Username>\AppData\Roaming\npm
Then open the bash and command npm start. Hope this will help.
I solved it by putting this in my PATH environment variable / user variable:
C:\Users\{userName}\node_modules\.bin
yarn expo start
Worked for me.
npx create-expo-app project-name

Cordova command not found - can not be used globally

so I have installed cordova using the following command to use it globally
sudo npm install -g cordova
and I get the following message
/Users/safwany/.node/bin/cordova -> /Users/safwany/.node/lib/node_modules/cordova/bin/cordova
cordova#5.1.1 /Users/safwany/.node/lib/node_modules/cordova
I keep typing cordova in the terminal but I am getting command not found. The only I can get it working is by typing the following:
/Users/safwany/.node/lib/node_modules/cordova/bin/cordova
Any idea how can I change that so I can use it globally by just typing cordova ?!
This seems to be a problem with the CHMOD rights of your folders. Try to own the folders like this:
sudo chown -R $USER /usr/local
sudo chmod -R 0775 /usr/local
after that, clear the npm cache with
sudo npm cache clear
finished? Go on by installing cordova again ->
sudo npm install -g cordova
type cordova into your terminal and everything should work like a charme.
Source: https://stackoverflow.com/a/19113963/3671726

Phonegap installation error (npm)

I have been searching for a solution for two days now to setup Phonegap on my Windows 8.1
system without any success.
Whenever I try to install Phonegap through npm I get an error that I think has to do
with Cordova(-lib).
To install Phonegap I had to install Node.js (v0.10.28) on my system. After this I opened up Windows Powershell and issued the following command like instructed on the Phonegap website:
npm install -g phonegap
Output: (This is the only part of the error)
error notarget No compatible version found: cordova-lib#'lorinbeer/cordova-lib.git#configparser_module'
error notarget Valid install targets:
error notarget ["0.21.2","0.21.3"]
error notarget
error notarget This is most likely not a problem with npm itself.
error notarget In most cases you or one of your dependencies are requesting
error notarget a package version that doesn't exist.
I also tried installing just Cordova through the npm and then install Phonegap, but that
didn't solve anything either.
Running the Powershell with administrator rights also didn't help and tried solutions of other people who also had problems setting up Phonegap, but nothing works.
I really hope that someone could help me out here.
Thanks in advance.
Download the older version. I think there was a problem in the new one
npm install -g phonegap#3.4
I tried this and worked for me.
I had the same issue yesterday. If you check npm-debug.log, you'll notice that there is a permission issue ("Permission denied") when npm tries to access the cordova-lib git repository url. Actually, cordova-lib is a dependency for phonegap. So, it can't install it and I think that's why you get that error.
So, I tried this: install cordova-lib first then Phonegap. Yet, it still won't work; npm does not seem to check if cordova-lib is installed before trying to do it.
At this point, what I could do is to change the repository from which it retrieves cordova-lib. Here is the NPM install syntax:
npm install <tarball file>
npm install <tarball url>
npm install <folder>
npm install <pkg>
npm install <pkg>#<tag>
npm install <pkg>#<version>
npm install <pkg>#<version range>
This means I can install from a tar.gz file. Great! So, I just went to this page https://www.npmjs.org/package/phonegap to check the phonegap repository and performed these steps:
Download the zip of phonegap-cli repo (https://github.com/phonegap/phonegap-cli/archive/master.zip)
Unzip it
Open the package.json file and find the cordova-lib entry in dependencies (line 32)
Change the value to 0.21.3 which is the last version.
Recreate an archive of the folder to the tar.gz format
Open your CLI and run this command:
npm install -g path/to/archive/phonegap-cli-master.tar.gz
It should work now.
Hope that help!
I had a similar problem today too on Mac, even after Lorenzo said it should be all fine. Just running this:
sudo npm install -g phonegap
... produced loads of errors like this:
error: file ./objects/pack/pack-48c0ff4147fb7e8922546c4a857b98a1cb48e01f.pack is far too short to be a packfile
I combined Lorenzo and arpan shah's solutions:
sudo npm install -g phonegap#3.4
sudo npm cache clean
sudo npm update -g phone gap
... and it seemed to magically work.
Problem
We published with a dependency on a branch of cordova-lib. This fork appears unavailable when lots of requests are coming through (I think). One way or another, it's unreliable.
Changing the dependency to 0.21.3 will cause commands to fail, but will allow the install.
Solutions
update the 'cordova-lib' dependency to the npm published version '0.21.3'
**note, this will allow the install, but other phonegap commands will fail
wait for about 20 minutes, then npm update -g phonegap
testing an update to resolve this issue
further updates momentarily
update
We've pushed version 3.5.0-0.20.3 which should resolve this issue
$ npm update -g phonegap
if that doesn't work, try
$ npm cache clean
and reinstall phonegap
I tryed above comamnds npm cache clear and reinstall phoegap. It downloaded all libs but not command line scripts (phonegap command had still 3.4 as version). I found that better was to give command: npm install -g cordova (v 3.5)!

Resources