Error while creating react-native cli project - react-native

Error:
Error: Couldn't find the "C:\Users\Admin\AppData\Local\Temp\rncli-init-template-oScLDz\node_modules\react-native\template.config.js file inside "react-native" template. Please make sure the template is valid. Read more: https://github.com/react-native-community/cli/blob/master/docs/init.md#creating-custom-template
Screenshot:

I have tried with npm using and it worked.
npx react-native init YourAwesomeProject --npm
After that
I have uninstalled yarn completely. Because you can install libraries using npm. So I have removed the yarn using
npm uninstall -g yarn

You can try:
Remove the global react-native CLI: npm uninstall -g react-native-cli or yarn global remove react-native-cli
And run again npx react-native init YourAwesomeProject
or
Run npx react-native-cli init YourAwesomeProject
Maybe these links can help:
https://github.com/react-native-community/cli#about
How to fix "Can not find module ".../template.config" error in React Native

surely you have your root a file or folder .yarn/ package.json package-lock.json
Remove them and try again rm -rf .yarn/ package.json .yarn/ package-lock.json

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.

How to remove unwanted expo modules

When creating an react native app with expo, expo installs many module that i don't need. Is there a way to remove these unwanted modules like barcode reader google sign in and google maps.
thanks
To remove a package from your node_modules directory, on the command line, use the uninstall command. Include the scope of the package is scoped.
Unscoped package
npm uninstall --save <package_name>
Scoped package
npm uninstall --save <#scope/package_name>
if need to know more about it then follow official Document here https://docs.npmjs.com/uninstalling-packages-and-dependencies#removing-a-local-package-from-the-packagejson-dependencies
npm uninstall <package name> works. It removes the expo module from your node_modules
for more reference
https://docs.npmjs.com/uninstalling-packages-and-dependencies
With NPM
$ npm uninstall jest
Shorthand version
$ npm r jest
With Yarn
$ yarn remove jest

npm install -g not working while uninstalling react-native-cli?

I am trying to uninstall the "react-native-cli" which I use for react-native projects! but I am not able to do so!
My environment is mac.
Here is what i have done so far!
Whether I type npm uninstall -g react-native-cli or sudo npm uninstall -g react-native-cli.
The terminal shows: up to date in 0.041s
When I type react-native init projectName, it still creates the project.
I think the command react-native init should not to work.
Anyone knows how to uninstall react-native-cli ?
Thanks in advance.
SOLUTION ONE !
not fully sure this will work! but try updating your npm first by doing
npm install npm
and after that try uninstalling the cli if that does not work then
SOLUTION TWO !
Here is another go around to solve the issue its a bit manual way
1: First run this
npm list -g
this will show the list of installed packages in your user folder
then check . using command+f if there is react-native-cil there
then do this
open /usr/local/lib/node_modules
This will open the root installed packages and you can manually find and delete the react-native-cli like this
If you are using yarn. You can do yarn global list then check that if any package contains react-native. Then run yarn global remove <package> to remove that package.
ex:
yarn global remove #react-native-community/cli
You can uninstall react native CLI using:
npm uninstall -g react-native-cli

Unable to resolve module `#babel/runtime/helpers/interopRequireDefault`

When creating a new react native project using the standard react-native init MyApp and running react-native run-ios for the first time I'm seeing the following error
error: bundling failed: Error: Unable to resolve module `#babel/runtime/helpers/interopRequireDefault` from `/Users/chrisedgington/Development/ReactNative/SixNationsPredictor/index.js`: Module `#babel/runtime/helpers/interopRequireDefault` does not exist in the Haste module map
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: `watchman watch-del-all`.
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.
4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.
at ModuleResolver.resolveDependency (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:209:1301)
at ResolutionRequest.resolveDependency (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:83:16)
at DependencyGraph.resolveDependency (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/node-haste/DependencyGraph.js:238:485)
at Object.resolve (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/lib/transformHelpers.js:180:25)
at dependencies.map.result (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:311:29)
at Array.map (<anonymous>)
at resolveDependencies (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:307:16)
at /Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:164:33
at Generator.next (<anonymous>)
at step (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:266:307)
I've tried running the suggested but still see the same issue. I've seen a few posts about similar issues but nothing specifically seems to say how to resolve the problem in react-native.
macOS: 10.13.6
node: 8.11.3
react-native-cli: 2.0.1
react-native: 0.57.1
Have a go and try:
npm add #babel/runtime
Or upgrade babel runtime:
"#babel/runtime": "7.0.0-beta.55"
I tried all the things mentioned above, and, I found myself here again tonight.
Running from a nrwl mono repo, I had to cd into the app that was having the problem and run.
jest --clearCache
You should first quit the metro terminal before executing
npm add #babel/runtime
npm install
You should add and install babel for your projects
npm add #babel/runtime
npm install
If The error is not fixed, Try:
npm start --reset-cache
The issue for me was that #babel/runtime was installed as a dev-dependency instead of just a normal (non-dev) dependency
Try to update your npm version first
npm update -g npm#version or sudo npm -gf update npm#version
and then just add the babel runtime at your react native project
npm add #babel/runtime
Try upgrading your packages. You could have an old package causing the problem:
yarn upgrade-interactive --latest
Current error message suggests these steps to fix this:
Clear watchman watches: watchman watch-del-all
Delete node_modules: rm -rf node_modules and run yarn install
Reset Metro's cache: yarn start --reset-cache
Remove the cache: rm -rf /tmp/metro-*
The last one solved it for me.
I had this problem today (April 2021), and I could solve it only by removing the webpack-node-externals package from my webpack configuration.
For me the solution was (Mac):
Stop IntelliJ
Enter terminal
Run: npx browserslist#latest --update-db -g
Run: npm cache verify
Start IntelliJ
If still not working:
Delete node_modules fron project if exists
Run: npm cache verify
Run npm install -f in project
Run: npx browserslist#latest --update-db -g
Problem:
I was in the middle of upgrading flow to typescript and I used #khanacademy/flow-to-ts to convert js files to ts. the lib not only changed the js files of the app but also it converted all js files in node_modules directory.
Solution:
I had to remove the node_modules and npm -i. This time when I checked the node_modules the interopRequireDefault.js file was there.
In case you are working with Yarn workspaces please note you are running react-native start from the right project...
Install latest Babel/runtime
=> install #babel/runtime
After that clean or reset the cache
=> npm start -- --reset-cache after
or
npm cache clean --force
I accidentally deleted my node_modules and package-lock.json. I used npm i to regenerate them and suddenly I was getting the above error. I solved it in two ways.
By uninstalling the app and using the following commands.
npx jest --clearCache
npm update
npm i
npx react-native run-android
By deleting the local repository and re-cloning it.
Hope this helps you.
I just uninstalled watchman. It worked for me.
brew uninstall watchman
Someone may find this helpful. I had the same problem while using turborepo and Expo.
Resolved it by adding 'node-linker=hoisted' to .npmrc.
Had this issue none of the above listed solutions worked for me, I had to go to node_modules/jest-haste-map/build/index.js
changed const crawl = canUseWatchman && this._options.useWatchman ? _watchman.default : _node.default;
to const crawl = canUseWatchman && this._options.useWatchman ? _node.default : _node.default;

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