11

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?

aslamjm
  • 121
  • 1
  • 1
  • 5
  • 1
    The issue is by having some globally installed Yarn/NPM packages. https://github.com/facebook/react-native/issues/34055#issuecomment-1165887713 – Rocky Aug 08 '22 at 09:54
  • Does this answer your question? [TypeError: cli.init is not a function for react native](https://stackoverflow.com/questions/72768245/typeerror-cli-init-is-not-a-function-for-react-native) – Iva Sep 13 '22 at 09:17

6 Answers6

16

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.

Alex Ivanov
  • 160
  • 4
  • The key for me was understanding that I need to ditch `react-native-cli` completely, and just let the `npx react-native` do the work – Charney Kaye Feb 16 '23 at 20:00
6

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.

2

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 
Iva
  • 2,447
  • 1
  • 18
  • 28
1

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.

Khurshid Ansari
  • 4,638
  • 2
  • 33
  • 52
0

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

  • 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](/help/how-to-answer). – Community Sep 17 '22 at 14:26
0

Replacing npx react-native with npx react-native@latest solved it for me.

mainak
  • 1,886
  • 2
  • 9
  • 19