Why react-native-cli giving errors?

Viewed 4689

I recently installed react native cli globally. When i tried to start a project using react-native init projectname or npx react-native init projectname it started downloading packages and creating the project. After completion it gave this error

    cli.init(root, projectname);
      ^

typeerror: cli.init is not a function
    at run (c:\users\showbi\appdata\roaming\npm\node_modules\react-native-cli\index.js:302:7)
    at createproject (c:\users\showbi\appdata\roaming\npm\node_modules\react-native-cli\index.js:249:3)
    at init (c:\users\showbi\appdata\roaming\npm\node_modules\react-native-cli\index.js:200:5)
    at object.<anonymous> (c:\users\showbi\appdata\roaming\npm\node_modules\react-native-cli\index.js:153:7)
    at module._compile (node:internal/modules/cjs/loader:1105:14)
    at object.module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at module.load (node:internal/modules/cjs/loader:981:32)
    at function.module._load (node:internal/modules/cjs/loader:822:12)
    at function.executeuserentrypoint [as runmain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47

What is causing this problem?

5 Answers

Probably you are have and using old react-native-cli, try to:

npm uninstall -g react-native-cli or yarn global remove react-native-cli

and then run npx react-native init projectname again.

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.

Just delete react native cli from globally and manually delete folder at: c:\users\showbi\appdata\roaming\npm\node_modules\react-native-cli

It is work for me perfectly.

remove react-native CLI globally (npm uninstall -g react-native-cli) and reinstall your app (npx react-native init app name)

The quick way out is

npx react-native init ProjectName --version 0.68.2

Because that error is from the new version 0.69.0 You can use upgrade to 0.69.0 later.

But the longer route is below:

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 
Related