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

Viewed 32480

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
8 Answers

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.

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

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 

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.

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

remove react native cli using this command

npm install -g react-native-cli

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

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

Just use the

npx react-native init YourProjectName --version 0.68.2

command to create the project on react native.

Related