Run expo-cli commands locally (using the local expo-cli) - react-native

I have expo-cli installed globally in node_modules. I created a React Native Project in which I also installed expo-cli locally (because its in the package.json dependencies of the project).
I noticed that whenever I run an expo-cli command in my project, the global expo-cli is the one always called. I know this because, I updated the local expo-cli to a newer version, and when I try to run a command that exists in the newer version and not the former, its says that the command is not recognized. Or when I run expo-cli -V it shows the version of the global expo-cli, not the newer version installed locally.
My question
How to force expo-cli commands to run with the locally installed version?

Add an npm script in your project's package.json for the expo command
"expo": "expo"
and use npm run expo ... to run you expo commands
In you project you can run npm bin / yarn bin to find the location of the locally installed binary files and invoke that directly.
./node_modules/.bin/expo ...

Related

Globally installation of packages with npm

I have a question regarding the package manager npm and the meaning of installing the package globally.
For example I work often with react, should I install react globally?
npm install -g react react-dom
Does this mean that next time when I do
npx creat-react-app my-app
It will get the package from the global or it does not matter and it will still download it locally inside my-app?
Because I really do not understand the idea behind installing globally.
Because if I want to use a package it should be mentioned in package.json, if it is in package.json it is then located in node_module ... so yeah ...
Could anyone give me better insight?
Thanks in advance
React library can be installed globally on your local machine. In development there is no real reason to do that since you might not have the latest version and this might cause issues.
Better practise is to use react on project level by using the command you stated above npx create-react-app my-app
If you push code to a server the package.json file will install the dependencies (React, React DOM,..) to build your project.
Read more here : https://create-react-app.dev/docs/getting-started/
If you've previously installed create-react-app globally via npm
install -g create-react-app, we recommend you uninstall the package
using npm uninstall -g create-react-app or yarn global remove
create-react-app to ensure that npx always uses the latest version.
You can check what packages are installed globally using:
npm list -g --depth 0

Can't remove Expo-cli

For some reasons I can't update or remove my version of Expo-cli.
I'm stuck on the 3.11.7 version. When I launch the update, it ends correctly but without being taken into account.
I've tested all the methods I've found but I haven't been able to uninstall it yet.
When I launch my project, it continues to launch normally with the v.3.11.7.
here are the commands line i already try :
yarn global remove expo-cli
npm -g uninstall expo-cli --save
sudo apt-get --purge remove expo-cli
yarn uninstall expo-cli
the expo --version commands is not working anymore ...
I need help please.
screenShot of the update request:
Please confirm OS. Mine is Windows 10.
Look in appdata for yarn or npm install directories. You can find the globally installed package files and delete expo.
Essentially an npm or yarn version other than the one you're using has installed the expo-cli and now your current version can't find it.
I solved this by deleting the expo files in that dir
Had the same problem. Here's how I decided it ( Win 10 )
Open cmd as administrator and type npm cache verify
After that type npm -g uninstall expo-cli --save, if it freezing terminate it.
Remove from your user folder ".expo" folder.
Than try npm -g uninstall expo-cli --save in cmd, if it freezing terminate it and open some expo project.
type yarn remove global expo-cli and then yarn add global expo-cli in the project
Hope it helps somebody else too.

How to check my create-nuxt-app version and upgrade it?

Background:
Previously, running yarn create nuxt-app myApp installs Nuxt v2.4.0 but today for example I noticed you downgraded to Nuxt v2.0.0. I did not change the development environment so I can not understand this behavior.
I did some search and complained elsewhere when I landed on this:
So the OP was asked to upgrade his create-nuxt-app version.
Question:
But how to do that ? How to check which create-nuxt-app I do have ?
Bonus:
I read why does Create-Nuxt-App installs nuxt version 1.4.5? and the answer says you: "Make sure you don't have a version of create-nuxt-app installed locally or globally." But how do you even install create-nuxt-app locally and globally ?
Info:
When I run npm list -g | grep 'nuxt-app' I do not get anything.
You are fine. You don't need to do anything.
If you create a project with create-nuxt-app you get "nuxt": "^2.0.0" in your package.json which means that your project automatically uses the latest 2.x.x version of nuxt. Also if there'll be an update to nuxt your project with update itself.
And to answer your two questions:
If you have create-nuxt-app installed in your project you can check its version using npm list create-nuxt-app (make sure you are in the project's directory). If it's installed globally you can check the version using npm list create-nuxt-app -g.
You can install create-nuxt-app locally using npm install create-nuxt-app and globally with npm install -g create-nuxt-app.
I finally found an answer here and there:
This execution screenshot from #manniL on Github is helpful also:
To check the existing NuxtJS Version of the project,
run yarn why nuxt on your terminal from the project root directory.
If you want to check for the VueJS version, install Vue Developer tool web extension, and check for Vue version.
source
If you have installed create-nuxt-app globally using npm, first uninstall that. Using the below command.
npm uninstall -g create-nuxt-app
Then reinstall it. And the latest version of the package will be installed.
npm install -g create-nuxt-app

errors after running expo start

I have installed latest node version and expo-cli but when I run the command expo start, it gives me this error:
Starting project at C:\Users\Ogacho\Desktop\sharelocation
Expo DevTools is running at http://localhost:19002
Your project is in SDK version >= 33.0.0, but the expo package version seems to be older.
Opening DevTools in the browser... (press shift-d to disable)
Error: React Native is not installed. Please run `npm install` in your project directory.
Couldn't start project. Please fix the errors and restart the project.
Set EXPO_DEBUG=true in your env to view the stack trace.
I have tried clearing my npm cache, deleting my node_modules folder and reinstalling...
This fixed it for me:
Run expo update 35.0.0. (Replace version with your desired version. 35.0.0 is the latest as of this post.) This updates expo, by updating app.json & package.json and installing the latest dependencies.
Referenced from:
https://docs.expo.io/versions/latest/workflow/upgrading-expo-sdk-walkthrough/
Also, check that:
your expo app is the latest version through the app/play store.
your expo cli is the latest version npm install -g expo-cli
Your project is in SDK version >= 33.0.0, but the expo package version seems to be older. If your expo-cli version is older than 2.21.2, run npm install -g expo-cli to get the latest version.
Or, you can change sdkVersion and dependencies to an older version to match the expo-cli doc.Run expo --version to get the expo-cli version. For example, if using expo-cli 2.19.5, you should
app.json, change sdkVersion to "32.0.0",
In package.json, change these dependencies:
{
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"expo": "^32.0.0",
"react": "16.5.0"
}
Delete your project’s node_modules directory and install again
Close your Expo CLI server
Run expo upgrade in your project directory (requires the latest version of expo-cli, you can update with npm i -g expo-cli).
Make sure to check the breaking changes section of this post!
Run expo start -c

'react-native' is not recognized as an internal or external command, operable program or batch file

I recently started with react-native. I install it using the tutorial on the Facebook site and everything works well for a day or two until this message comes up:
'react-native' is not recognized as an internal or external command,
operable program or batch file.
Nothing works except uninstalling everything and starting all over again. The environments are ok and work (npm, choco, etc.). I have also tried removing and adding react-native to environment variables, restarting, and running cmd in administrator mode, but nothing so far. I should add that I use windows 10 64-bit.
I had the same issue and tried the following but didnt work
Adding npm path to my Environment variables; both system and user
Re install npm and react-native-cli
Both didn't work for me, im using Windows 10;
Solution that worked for me is to install react-native-cli globally
You can install it globally by using the below command:
npm install -g react-native-cli
You can simply use npx react-native <command> it will work
npm install -g react-native-cli
But dont forget to restart command promprt
Your system or user environment PATH variable was edited, you can uninstall NodeJs and install it again or add the below path to the end of PATH variable into user variables the restart the Windows :
C:\Users\[USER-NAME]\AppData\Roaming\npm
this should work.
You need to setup the npm path in your environment variables. Please look at the images down below
Then follow the command : for installing -g ( global ) for cli in your system
npm install -g react-native-cli
I get the same error right off the bat on Windows 10 running in cmd window in adminstrator mode, however there is also a bash shell version of react-native that worked for me in a git bash window.
cmd:----------------------------------------------
C:\Users\David\Documents\react>where react-native
C:\Users\David\AppData\Roaming\npm\react-native
C:\Users\David\AppData\Roaming\npm\react-native.cmd
C:\Users\David\Documents\react>react-native init AwesomeProject
'react-native' is not recognized as an internal or external command,
operable program or batch file.
git bash:----------------------------------------
David#CYBER-PC ~/Documents/react
$ react-native init AwesomeProject
This will walk you through creating a new React Native project in c:\Users\David\Documents\react\AwesomeProject
Installing react-native package from npm...
Setting up new React Native app in c:\Users\David\Documents\react\AwesomeProject
AwesomeProject#0.0.1 c:\Users\David\Documents\react\AwesomeProject`-- react#15.3.1
To run your app on iOS:
cd c:\Users\David\Documents\react\AwesomeProject
react-native run-ios
- or -
Open c:\Users\David\Documents\react\AwesomeProject\ios\AwesomeProject.xcodeproj in Xcode
Hit the Run button
To run your app on Android:
Have an Android emulator running (quickest way to get started), or a device connected
cd c:\Users\David\Documents\react\AwesomeProject
react-native run-android
npm install -g react-native-cli
I had to add the %APPDATA%\npm folder to my PATH on Windows 10. Global modules are installed there.
If uninstalling and installing again the npm did not work on you, try adding %APPDATA%\npm to path (Environment variables) then quick reboot/restart. System Reboot should really be part of the process. This worked on my end.
Install :
npm install -g react-native-cli
Uninstall :
npm uninstall -g react-native-cli
If you are following the getting started guide for Windows/Android, they recommend installing nodejs via Chocolatey. But Chocolatey likes to have administrator rights when it installs things. If you're just a regular user, this seems to interfere with how npm installs react-native-cli. In my case, the react-native command was only recognized when I launched a command prompt as admin.
What I did to fix:
launched command prompt as admin
uninstalled react-native-cli globally: npm uninstall -g react-native-cli
uninstalled nodejs via Chocolatey: choco uninstall nodejs
Now, as a regular user without admin rights:
installed nodejs via the nodejs website (not Chocolatey)
installed react-native-cli globally: npm install -g react-native-cli
I uninstalled node.js and then reinstalled it, and it worked like a charm
just uninstall the node.js and reinstall it..
then install the cli package typing command
npm install -g react-native-cli..
now you are ready to make your project.
To make project open a folder from your drive wherever your folder is located.
Then type command
react-native init albums
it will create a project for you inside your directory.
None of the above mentioned solutions worked for me. What did work was to remove nodejs, and reinstall it via Chocolatey with the following command:
PS > choco install -y nodejs.install python2 jdk8
> npm install -g react-native-cli
C:\Users\user\AppData\Roaming\npm\react-native ->
C:\Users\user\AppData\Roaming\npm\node_modules\react-native-cli\index.js
+ react-native-cli#2.0.1
added 41 packages from 15 contributors in 4.528s
I had this problem also becuase I restored my files from a previous OS installation. My problem was a wrong prefix in my C:\Users\user_name\.npmrc file.
Run npm config list and make sure that all your npm config variables are leading to the correct file paths. Delete the .npmrc file if you want have it to go back to the defaults. That's what I did and react-native command is working for me again.
I hope this helps.
i have no clear idea but below steps worked for me.
delete Node Modules
Uninstall react-native cli. This is Recommended in the react-native Documentation
"If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues."
npm uninstall -g react-native-cli
clean gradlew. in your project folder, go to the android folder by typing cd android
and run gradlew clean
move back to your project folder cd .., then run
npx react-native run-android
these steps worked for me. took some time when running first time.
use node.js stable version or recommended version.
On window 10, nodejs>11 global node libraries seems to be installed in C:\Users\your_user_name.npm-global. So you need to set the variable to point to that path
I had problems because of this strange mistake.
I checked to see if it was globally loaded again
I didn't delete all packages
I even deleted C:\Users[USER-NAME]\AppData\Roaming\ npm manually, but there was no solution.
The only thing that is the solution is to use the current version of node.js.
uninstall nodejs completely(restart your pc) and reinstall it using chocolatey and follow other commands from https://facebook.github.io/react-native/docs/getting-started.
worked perfectly fine for me!
Even if you have installed react-native globally and still get the same try adding path of npm module (C:\Users\your user name\AppData\Roaming\npm) to system variables instead of user variables.
I know it's too late, anyway
Make sure you've added the path of the NPM in system variable rather than user variable in the System Environment Variables.
PATH : C:\Users\user_name\AppData\Roaming\npm
Open a the command prompt and type: npm config list:
Get the path underlined in red and add it your system path (change two back slashes into one), for example: C:\Users\YOURNAME\AppData\Roaming\npm.
This solved the issue for me
I just wrote "react-native -v" to console to check have I still react-native and then just I wrote "react-native run-android" again and this time it worked. Yes just that. React native is terrible technology.
Looks like I have uninstalled react native cli by mistake, I tried all answers mentioned above, but the below command worked for me.
npx react-native run-android.
Solution
I was facing 'react-native' is not recognized as an internal or external command,operable program or batch file error when I was running react-native start in VsCode.
I Solved it by running npm install -g react-native-cli in PowerShell
Steps to follow
run PowerShell as admin (important step)
run running npm install -g react-native-cli in PowerShell
close VsCode and rerun it
that's all!
I solve this problem by running
npm install -g react-native-cli
then another error appears
Command run-android unrecognized.
I fixed this error by
npm install
Use npx before your command
npx react-native
Not just
react-native
if you faced the same issue as me just type :
npm i react-native
then try to create a new project as its recommended by the react native doc by typing :
npx react-native init yourProjectName
this should resolve your problem
hope this was helpful