Running yarn add requires sudo - yarnpkg

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

Related

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

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.

How Can I Solve Permission Denied in React Native Project?

anyone faced this issue after a run
react-native run-android/ios
android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java
(Permission denied)
when i write sudo before any command like npm install/yarn add etc it's work very well
otherways i got errors related to Permission
You might check the permissions on android/gradlew
They should be 755 not 644
Run chmod 755 android/gradlew inside your app root folder
then run react-native run-android
And it should work again
Finally remove the node modules and re-install using rm -rf node_modules && npm install
It looks like you have no permission- try this
sudo chmod -R 777 {path}
deleting node_modules folder from project and then running command npm i worked for me in existing react-native project

"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

nodejs issue: trying to install with npm with windows and getting eacces error

I'm getting an error when trying to install a package with npm and I'm getting EACCES permission denied C:\Program Files\nodejs
I'm running 'npm install mongoose' for example and getting this error when running in that directory.
I'm new to this so any help is appreciated!
Thanks!
You should change the permissions on the folder nodejs is installed and give full access to your normal user account. You should avoid running npm as an administrator.
You need to run cmd.exe as administrator. (rightclick, run as admin)
You also don't need to travers to node's directory, just do npm install -g [package](-g if for a global install.)

Resources