TypeError: cli.init is not a function for react native
Asked Answered
A

19

100

While running npx react-native init appName in MacBook air M1 chip

TypeError: cli.init is not a function
at run (/opt/homebrew/lib/node_modules/react-native-cli/index.js:302:7)
at createProject (/opt/homebrew/lib/node_modules/react-native-cli/index.js:249:3)
at init (/opt/homebrew/lib/node_modules/react-native-cli/index.js:200:5)
at Object.<anonymous> (/opt/homebrew/lib/node_modules/react-native-cli/index.js:153:7)
at Module._compile (node:internal/modules/cjs/loader:1112:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:834:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
Atlantic answered 27/6, 2022 at 7:16 Comment(1)
Same issue occurring in Windows 10. Using react-native-cli to init a projectFariss
L
183

install new react-native global

npm uninstall -g react-native-cli

install new react-native global

npm install -g react-native-cli

npm install -g react-native

and create project again

npx react-native init AwesomeProject
Leporid answered 5/7, 2022 at 2:47 Comment(4)
> if you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues.Figurative
When I created a new React Native Project my Ios/Anroid folders were not created, which was head scratching because I've done this before a few times already. Your solution was a huge help and should be on top due to how easy the issue was to solve with your help thank you.Ping
The key for me was understanding that I need to ditch react-native-cli completely, and just let the npx react-native do the workIntramural
This worked for me. TnxCharwoman
A
50

Need to clean global environments with following commands:

yarn global remove react-native

yarn global remove react-native-cli

npm uninstall -g react-native

npm uninstall -g react-native-cli

check that nothing related to react-native presents in these lists:

yarn global list

npm -g list

install new react-native global

npm install -g react-native-cli
npm install -g react-native

then you can run:

npx react-native init ProjectName 
Atlantic answered 27/6, 2022 at 7:30 Comment(3)
It didn't work- Did it work for you?Conlen
It worked- Didn't it work for you?Neel
It didn't work too. Needed this one: github.com/facebook/react-native/issues/…Ul
T
18

This happened because you have an old version of react native, So you need to remove the react native version globally and install it again.

Steps to fix your problem:

if you use Yarn:

First Step: Check the Global installation list:

yarn global list

if you found react-native and react-native-cli so go to the next step and remove them globally

Second Step:

yarn global remove react-native
yarn global remove react-native-cli

Third Step: Install them again

yarn global add react-native
yarn global add react-native-cli

if you use NPM:

First Step: Check the Global installation list:

npm -g list

if you found react-native and react-native-cli so go to the next step and remove them globally

Second Step:

npm uninstall -g react-native
npm uninstall -g react-native-cli

Third Step: Install them again

npm install -g react-native
npm install -g react-native-cli

Note: Delete the old project you create, then create it again. Every thing will go fine.

Tinner answered 18/7, 2022 at 10:3 Comment(0)
S
11

That is error is from the new version 0.69.0 You can use npx react-native init ProjectName --version 0.68.2 and then upgrade to v 0.69 later.

Soften answered 23/10, 2022 at 8:19 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Carmelacarmelia
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Beano
P
4

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 @react-native-community/cli

React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using npx, which ships with Node.js. Let's create a new React Native project called "AwesomeProject":

npx react-native@latest init AwesomeProject

This is not necessary if you are integrating React Native into an existing application, if you "ejected" from Expo, or if you're adding Android support to an existing React Native project (see Integration with Existing Apps). You can also use a third-party CLI to init your React Native app, such as Ignite CLI.

Protest answered 7/3, 2023 at 6:17 Comment(1)
I vote +1 for this answer. Since the latest react-native (0.71.3) no longer requires [email protected]. Being said, remove the cli and npx react-native@latest init AwesomeProject works in my case. My environment: MacOS 10.14.6 Node v.14.19.0 NPM 6.14.16Thirteenth
M
4

I think latest stable version is 0.68.2, so create project at this level using command given below

npx react-native init ProjectName --version 0.68.2

Mirilla answered 18/4, 2023 at 9:42 Comment(1)
Thanks, it worked for me. Strangely, npm uninstall -g react-native-cli @react-native-community/cli npx react-native@latest init AwesomeProject did not work.Cheater
B
3

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 @react-native-community/cli

Link Here

Boorish answered 27/1, 2023 at 8:41 Comment(0)
R
2

Should run:

yarn global list or npm global list

And uninstall all cli's of the react-native in list, after run:

yarn global add @react-native-community/cli
Razorbill answered 11/8, 2022 at 18:25 Comment(0)
C
1

Do-> yarn global remove react-native-cli && npm uninstall -g react-native-cli

Then-> yarn global add @react-native-community/cli or npm install -g react-native-cli

Cardoza answered 23/10, 2022 at 15:59 Comment(0)
C
1

I was able to clear the issue by uninstalling the cli and only installing react-native

npm uninstall -g react-native-cli
npm install -g react-native

then

react-native init ProjectName

I am using

react-native -v
10.1.3
Clamorous answered 20/2, 2023 at 4:35 Comment(0)
C
1

If you have already installed react native globally, uninstall it by: npm uninstall -g react-native-cli

Then install it again by: npm install -g react-native-cli

Then you can create your new project by the following command: npx react-native init <project_name>

Cothran answered 6/5, 2023 at 6:12 Comment(0)
G
1
yarn add react-native --exact

I re-installed react native with --exact and this fixed my problem

Gabbi answered 22/5, 2023 at 23:24 Comment(0)
O
0

remove react native cli using this command

npm uninstall -g react-native-cli then npm install -g react-native

no need for it now as.

React Native has a built-in command line interface, which you can use to generate a new project.

Check reactnative.dev

Oleograph answered 23/8, 2022 at 7:47 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Carmelacarmelia
O
0

if you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues. You can run the following command:

npm uninstall -g react-native-cli @react-native-community/cli

or

yarn global remove react-native-cli @react-native-community/cli

Follow the Reference: https://reactnative.dev/docs/environment-setup

Osterhus answered 9/9, 2022 at 23:20 Comment(0)
B
0

I tried every solution above mentioned none of them didn't worked actually except this(npx react-native init ProjectName --version 0.68.2)

But finally i fixed my issue by deleting node modules from my user folder .Go to user/username/and delete node modules and old projects or any package.json files.

then now run :- npx react-native@latest init projectname

Bondswoman answered 12/5, 2023 at 5:10 Comment(0)
V
0

npx react-native init AwesomeProject --version 0.68.2 solved my problem

Veronique answered 11/8, 2023 at 10:57 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Carmelacarmelia
S
0

I didn't remember that I installed it with brew and that was the problem, it must be deleted from there as well

First uninstall:

brew remove react-native-cli
npm uninstall -g react-native-cli
npm uninstall -g react-native

Next step, install:

npm install -g react-native
npm install -g react-native-cli
Steeplebush answered 17/1 at 22:25 Comment(0)
R
0

In command Prompt,

  1. uninstall cli react-native global code---> npm uninstall -g react-native-cli

  2. Install cli in command prompt a.code==> npm install -g react-native-cli, b.code==> npm install -g react-native

  3. Finally create project,
    code==>npx react-native init AwesomeProject

Rusell answered 26/4 at 9:36 Comment(0)
S
-2

Try with this latest command.

npx react-native@latest init ProjectName

Worked for me!

Screenplay answered 27/2, 2023 at 9:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.