Packager won't start - react-native

I guess I upgraded node at some point and now when I try to run the packager with npm start it's complaining with:
$ npm start
react-native start
Looks like you installed react-native globally, maybe you meant react-native-cli?
To fix the issue, run:
npm uninstall -g react-native
npm install -g react-native-cli
Node 5.1.0, npm 3.3.12 and react-native 0.15.0

It looks like the preferred way to start the packager now for an IOS app is by hitting the run button in xcode itself or using the following command:
react-native start

I'm using:
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
}

I got the same error.
It turns out it's because npm finds another react-native inside node_modules due to being started with a vastly different environment.
So I changed my package.json to look like this:
"scripts": {
"start": "$NVM_BIN/react-native start"
}

Did you follow the instructions and do?
npm uninstall -g react-native
npm install -g react-native-cli
I say this, because I kept making the error of installing react-native instead of react-native-cli.

export PATH="/Users/my-mac/Library/Android/sdk/platform-tools":$PATH
./adb reverse tcp:8081
./adb start-server
./adb devices

I've been in this situation or days, no solution yet, so I had to downgrade to Expo#19.0.0, and it worked
if you like to follow my steps:
in package.json update devDependencies:
"jest-expo": "19.0.0"
"react-native-scripts": "1.0.0"
in package.json update dependencies:
"expo": "19.0.0"
in app.json update the sdkVersion to 19.0.0

In my case, I would use npm start or react-native start and it would install the debug version of my app just fine, but the packager wouldn't start.
I found out it was because another process was using my 8081 port.
Check what processes are using that port if you're not specifying another port with lsof -i tcp:8081 in terminal, or any other tool to find out what processes are using what port.

Related

eject command not found in create-react-app -- how to add to package.json?

I get this error after installing create-react-app, and trying to run "npm run eject"
eject: command not found.
How do I edit package.json to run the command I found in the documentation?
I found a work-around: run the script, manually, found in node_modules/react-scripts/scripts/eject.js.
node ./node_modules/react-scripts/scripts/eject.js
facebook's github indicates that the global install of create-react-app would interfere with CRA installation; and so I ran:
npm rm -g create-react-app
as suggested on facebook's github here:
https://github.com/facebook/create-react-app/issues/8088#issuecomment-562189517
(and then reinstall CRA)
You have to install
https://github.com/ramyareye/react-native-eject
yarn add react-native-eject
yarn react-native eject
Instead of npm try with npx
npx react-scripts eject
Above command worked for me.

'electron-packager' is not recognized as an internal or external command

I recently started using electron. I have successfully completed the 1st phase by creating a hello world app (included files index.html, main.js, package.json). Now I am trying to package the app using electron-packager but getting this error
Steps I have followed:
Created a project directory named helloworld.
Initialized the project directory using npm init command.
Then installed electron using npm install electron --save-dev.
Then created the javascript and html files as main.js and index.html respectively.
Then used npm start to execute the application.
Then installed electron-packager using npm install electron-packager.
Now the problem is coming in this step when i am trying to pacakge the app using command electron-packager .
Perform a global package install:
npm install -g electron-packager
The -g flag tells NPM to install the package globally which makes the command electron-packager available in your PATH.
If you don't want to do a global install you can install it locally and run with npx.
npm install -D electron-packager
npx electron-packager .
Alternatively, you can reference it straight from the node_modules folder (not recommended).
./node_modules/electron-packager/cli.js
There are two cases to make it work...
As discussed above, install electron globally using -g,
i.e. using npm install -g electron-packager
Change in your package.json:
"scripts": {
"start": "electron-packager ."
},
Then type in the command npm start.
This way it worked for me..
If you have installed it locally with:
npm install electron-packager
Then, it's not gonna work, install it globally as a cli:
npm install -g electron-packager
You can also get it through:
"node_modules/electron-packager/cli.js" . --all --asar
After All, if you don't get it working, install electron-packager.
Then, go to your package.json. And beneath your start scripts. Make another string named "build" and give it a value of the electron-packager command you want to run:
...
"scripts": {
"start": "electron .",
"build": "electron-packager . --asar --all"
},
...
Then, go in command prompt or terminal or bash.
Then, type:
npm run build
I might be totally off with it but my fix was that I put the dot without space just make sure in you package.json file its "start": "electron ."
Fixed it for me at least
You've to install electron-packager globally, that's why it shows 'electron-packager' is not recognized as an internal or external command
For this, you have to install electron-package globally
You can install globally by using -g option.
Example:-
npm install -g electron-packager OR npm i -g electron-packager //i stands for install
In my case it doesn't worked after npm global installation.
On the electron-builder Readme page it's recommended to install with yarn.
Yarn is strongly recommended instead of npm.
yarn add electron-builder --dev
Also we can put folder directly to PATH. On Windows 10:
Search with word "environment" and open Edit the environment variables.
Select, edit and Add new value C:\Users\USER_NAME\AppData\Roaming\npm to variable Path. Replace USER_NAME with your Windows username.
Then we might need to restart or logout.
Also in my case I enabled script execution on Windows 10 with instruction on answer below:
PowerShell says "execution of scripts is disabled on this system."

gulp command not found

Windows 10 pro x64
I ran the following commands
npm install --global gulp-cli
npm init
Then I changed directory to my project:
npm install --save-dev gulp
then tried to run gulp and got
-bash: gulp: command not found
my package.json file reads
{
"name": "riad-kilani_v4-child",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"dependencies": {
"gulp-cli": "^1.2.2"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-sass": "^2.3.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Any ideas on whats going on here?
I solved the problem creating an alias in ~/.bashrc like this:
alias gulp="node /home/deploy/app/node_modules/gulp/bin/gulp.js"
Just put the alias in the end of the .bashrc file, then run:
source ~/.bashrc
Test with:
gulp -v
You should see something like this:
[15:46:39] CLI version 3.9.1
[15:46:39] Local version 3.9.1
On MacOS Catalina v10.15.2, the following global install with sudo worked for me.
sudo npm install gulp -g
So I ran into this issue as well and none of the top answers were helping. Everything was installed, uninstalled, restarted, installed globally, etc., etc.... and still got the gulp command not found error. So I opened the package.json file and put in the following after the name field:
"scripts": {
"start": "gulp"
},
And then I ran npm start in git bash.
Everything ran correctly, I got my dev view in my browser # localhost and all was right with the world.
Hope this helps!
I had got into the same issue. Even after npm install gulp -g and npm install bower -g, both gulp and bower showed the error.
Here is the thing to remember.
1. gulp and bower command does not run in root (sudo). Switch back to the system user and the run it
2. Make sure the folder where you are running gulp has the user permission. else the permission will be denied
Hope this works for you
I'm using Ubuntu and found the error of -bash: gulp: command not found, too. But it became work after npm install gulp -g
I managed to fix this problem using simple 3 commands found from https://gulpjs.com/
npm install gulp-cli -g
npm install gulp -D
npx -p touch nodetouch gulpfile.js
Hope it helps someone else.
ps: it is not mandatory to use the 3rd command in order to fix the problem.
You can try:
To run this command in the terminal: npx gulp
If want know more visit this Link
For anyone else who runs into this just run npm install and npm update.
I ran npm rm --global gulp to clear out any version conflicts and then ran npm install --global gulp-cli. This did a clean install of gulp and it works flawlessly now.
On MacOS Sierra v10.12.6, the following global install with sudo worked for me.
sudo npm install gulp -g
You didn't mention which versions of node/npm you are using.
We had a similar problem and seems that gulp-sass had to be upgraded.
You can try:
rm -fr node_modules package-lock.json && npm install -g gulp-sass#3.0.0 && npm install

react native unable to run-android

I have followed guide here to setup react-native 0.23 https://facebook.github.io/react-native/docs/getting-started.html#content
I tried to run
react-native run-android
and got the following
Looks like you installed react-native globally, maybe you meant
react-native-cli? To fix the issue, run: npm uninstall -g react-native
npm install -g react-native-cli
and I tried above command to uninstall and install but still getting the samething.
I google and found some solution at Packager won't start
Tried:
"scripts": {
"start": "$NVM_BIN/react-native start"
}
and
react-native start
both still didn't work. For iOS no problem as I fired up XCode to run it. I have also installed VirtualBox and Genymotion as emulator.

React Native: Command `run-ios` unrecognized

I have two different ReactNative-Projects:
a) a project from januar 2016
b) a complete new react-native project
from now (march 20th 2016)
Within the new project the cli tool of react-native contains the command "run-ios" next two "run-android", but not on the older project from januar 2016. On the older one there is not "run-ios" command available:
$ react-native run-ios
Command `run-ios` unrecognized
Usage: react-native <command>
I already ran "react-native upgrade" without any issues.
How can i get the command "run-ios" also in older projects?
Just update the version of react native in your project with the following command:
$> npm install --save react-native#latest
What caused this for me was running npm install --save [package] when actually the system has previously been using yarn instead of npm.
To solve this I just deleted the node_modules folder and ran: yarn install and after that react-native run-ios (or android) works fine.
$ react-native run-ios
If you get this kinda error:
"Command run-ios unrecognized. Make sure that you have run npm
install and that you are inside a react-native project".
In terminal, make sure you are inside a react-native project directory.
Execute this cmd:
$ react-native -v
react-native-cli: 2.0.1
react-native: n/a - not inside a React Native project directory
$ npm update
$ react-native -v
react-native-cli: 2.0.1
react-native: 0.44.0
$ react-native run-ios
This may sound silly, but make sure you cd to your project directory. If that fails then perform the npm install in the other answers.
I found a solution that works for me.
Update the version of react native in your project:
npm install --save react-native#latest
then upgrade your npm version
npm i npm#latest -g
then move directory folder 1 level up, type
cd ..
make a new react-native installation folder
react-native init NewProject
then go to your project folder(NewProject), after that
react-native run-ios
should work fine.
This happens when the project has an older version of react native. You can update the react version or for people who do not want to upgrade, just open the .xcodeproj file in iOS dir and hit the play button in the Xcode.
In my case, it was an issue with the package.json file. I deleted a section during a test. I recover a previous file with the deleted section and everything was working again.
this works for me
sudo npm install -g react-native-cli --force
then
react-native run-ios
In my case, I am using monorepo with multiple packages in a single repo. I solved this error by
Deleting the packages/myapp/node_modules
running yarn install from the project root. Not inside packages
its solved. Now can run yarn ios or yarn android commands
Note:
For autolinking libraries you need to have all of your dependencies in root package.json file also copied to packages/myapp/package.json file. See https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#how-can-i-use-autolinking-in-a-monorepo
Example:
"dependencies": {
"#react-native-community/datetimepicker": "^3.5.2",
"#react-native-community/masked-view": "^0.1.11",
"#react-navigation/native": "^5.9.4",
"#react-navigation/stack": "^5.14.5",
"#reduxjs/toolkit": "^1.6.0",
"#voximplant/react-native-foreground-service": "^2.0.0",
"axios": "^0.21.1",
"babel-eslint": "^10.0.3",
"eslint-config-airbnb": "^18.0.1",
"eslint-plugin-import": "^2.18.2",
...
...
but make sure NOT TO COPY
"react-native-cli": "^any version",
otherwise react-native-cli would collide and you will continue to see error like
Command `run-android` unrecognized. Make sure that you have run `npm install` and that you are inside a react-native project.
error Command failed with exit code 1.
or
Command `run-ios` unrecognized. Make sure that you have run `npm install` and that you are inside a react-native project.
error Command failed with exit code 1.
I created a brand new react-native project using
$ react-native init projectName
and ran from root of the project
$ react-native run-ios
Everything worked fine and iOS simulator fired up as expected.
Than I installed prop-types node module using npm install prop-types --save. Re-ran $ react-native run-ios and ran into this error Command run-ios unrecognized
Solution:
From the root of my project, removed node_module and re-installed modules using npm. Commands below
$ rm -rf node_modules/
$ npm install
$ react-native run-ios
For me, Xcode was already running.
Close the Xcode and then in the terminal, make sure you are inside a react-native project directory and then execute react-native run-ios command
For me, the only thing that worked was to checkout again my repository from zero and run:
npm install -g react-native-cli yarn
yarn
git submodule update --init --recursive
What caused this for me was running npm install --save axios when actually the system was previously using yarn instead of npm.
To solve this, instead of deleting the node_modules folder, which can lead to more problems, and if you prefer to run npm anyway or don't have a preference either way, the error should have instructed for you to run npm install. If you literally follow those instructions, you will be able to run: react-native run-ios afterwards.
I also fell in this error and the reason was
I was using yarn link command in wrong folder
Delete the node-modules. Its because the packages are not installed.
rm -rf node_modules
npm install
then run your project
react-native run-ios