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

Description

npx react-native init Name throws when creating a template with RN v0.69

Version

0.69.0

Output of npx react-native info

yarn v1.22.19 react-native-cli: 2.0.1 react-native: n/a - not inside a React Native project directory So I can’t npx react-native info

Steps to reproduce

Just do npx react-native init Name using macOS 12.4, Intel.

Snack, code example, screenshot, or link to a repository

/Users/user/.config/yarn/global/node_modules/react-native-cli/index.js:302 cli.init(root, projectName); ^

TypeError: cli.init is not a function at run (/Users/user/.config/yarn/global/node_modules/react-native-cli/index.js:302:7) at createProject (/Users/user/.config/yarn/global/node_modules/react-native-cli/index.js:249:3) at init (/Users/user/.config/yarn/global/node_modules/react-native-cli/index.js:200:5) at Object.<anonymous> (/Users/user/.config/yarn/global/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

Node.js v18.4.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 22
  • Comments: 51 (1 by maintainers)

Most upvoted comments

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.

/Users/user/.config/yarn/global/node_modules/react-native-cli/index.js:302

The issue is caused by having some globally installed Yarn/NPM packages which is not generally recommended.

Depending on the commands you installed in the past with -g, you should be able to cleanup your environment with a combination of those commands:

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

Make sure the global packages are clean with:

yarn global list
npm -g list

(check that nothing react-native related is available in those lists).

all of them not work

I am also getting same issue npx react-native init HeyGroopApp --template react-native-template-typescript

/usr/local/lib/node_modules/react-native-cli/index.js:302 cli.init(root, projectName); ^

TypeError: cli.init is not a function at run (/usr/local/lib/node_modules/react-native-cli/index.js:302:7) at createProject (/usr/local/lib/node_modules/react-native-cli/index.js:249:3) at init (/usr/local/lib/node_modules/react-native-cli/index.js:200:5) at Object.<anonymous> (/usr/local/lib/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

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.

Thank You

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

then install again

yarn add global react-native yarn add global react-native-cli npm install -g react-native npm install -g react-native-cli

good luck

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.

Thank You

Hi, How to upgrade ?

/Users/user/.config/yarn/global/node_modules/react-native-cli/index.js:302

The issue is caused by having some globally installed Yarn/NPM packages which is not generally recommended. Depending on the commands you installed in the past with -g, you should be able to cleanup your environment with a combination of those commands:

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

Make sure the global packages are clean with:

yarn global list
npm -g list

This worked for me. Thanks!

Este comando funcionou perfeitamente aqui npx react-native init ProjectName --version 0.68.2

Actually latest version (0.69.0) still not working. so please try below steps

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

then install again

yarn add global react-native yarn add global react-native-cli npm install -g react-native npm install -g react-native-cli

You might be using old react-native-cli. Maybe you should try uninstalling and react-native-cli globally and reinstalling it. use: npm uninstall -g react-native-cli to uninstall and npx react-native init yourprojectname to reinstall. You will be prompted to install react-native again, accepted it and proceed.

npx react-native init ProjectName --version 0.68.2 worked for me

This error is happening on windows as well! I temporarily fixed it by downgrading to last version

Even if you down grade the version. Once you try to run the project if fails anyway. I think it’s related to the new Mac OS upgrade and the hardening of permissions. Please note here that I’m presuming this is only happening on Mac.

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 . it works for me. good luck guys.

from : https://reactnative.dev/docs/environment-setup

Are there any fixes in the latest version? When creating a project in IntelliJ, the same issue occurs with npx --package react-native-cli react-native script for installing the react-native module.

(I’m using npx --package react-native-cli react-native --version 0.68.2 instead)

TY @emorilebo, That worked & I didn’t even realize that I had the old version of the react-native-cli installed

I am not sure if status = closed is correct, until they fix the current version.

update react-native and react-native cli as global

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.

This worked for me. Thanks!

I had the same issue on windows… using version 0.68.2 solved the problem