Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: cli.init is not a function #34055

Closed
marandaneto opened this issue Jun 23, 2022 · 51 comments
Closed

TypeError: cli.init is not a function #34055

marandaneto opened this issue Jun 23, 2022 · 51 comments
Labels
Impact: Misconfiguration When the issue is due to a misconfig for the user Platform: macOS Building on macOS. Resolution: Answered When the issue is resolved with a simple answer

Comments

@marandaneto
Copy link

marandaneto commented Jun 23, 2022

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. (/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

@Naveen562117
Copy link

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. (/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

@OmarBasem
Copy link

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.

@evildevilnova
Copy link

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 it's working

@Naveen562117
Copy link

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

@plipustel
Copy link

all of them not work

@stefanoHTB
Copy link

getting the same error!

@spiroalisandratos
Copy link

spiroalisandratos commented Jun 24, 2022

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.

@krishna19982904
Copy link

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

Could you please explain how to upgrade to 0.69.0 later and what exactly is causing this issue due to version change?

@stefanoHTB
Copy link

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

@krishna19982904
Copy link

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.

Could you please explain how to upgrade to 0.69.0 later and what exactly is causing this issue due to version change?

@lcrossi
Copy link

lcrossi commented Jun 24, 2022

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

@chungtvdev
Copy link

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 ?

@hnasirzade310
Copy link

thank you so much

@cortinico cortinico added Platform: macOS Building on macOS. Impact: Misconfiguration When the issue is due to a misconfig for the user Resolution: Answered When the issue is resolved with a simple answer and removed Needs: Triage 🔍 labels Jun 24, 2022
@cortinico
Copy link
Contributor

/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).

@Bsingh2697
Copy link

Bsingh2697 commented Jun 25, 2022

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

Could you please explain how to upgrade to 0.69.0 later and what exactly is causing this issue due to version change?

just change the package version in package.json and npm install and if u wish u can remove node_modules before npm install

But anyways 69 doesn't fix the problem yet, so continue with 68.2

@spiroalisandratos
Copy link

spiroalisandratos commented Jun 25, 2022 via email

@devinkg
Copy link

devinkg commented Jun 25, 2022

/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).

This worked for me. Thanks!

@vmobeedeveloper
Copy link

vmobeedeveloper commented Jun 27, 2022

/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!

@Hassaan0
Copy link

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!

@kevinsiregar22
Copy link

update react-native and react-native cli as global

@kevinsiregar22
Copy link

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

@trongduc03
Copy link

trongduc03 commented Jul 2, 2022

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.

Many thanks.

@temiNoah
Copy link

temiNoah commented Jul 2, 2022

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.

thanks so much

@temiNoah
Copy link

temiNoah commented Jul 2, 2022

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 ?

from the below info:
info React Native v0.69.1 is now available (your project is running on v0.68.2).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.69.1.
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.68.2.
info To upgrade, run "react-native upgrade".

@manisha351
Copy link

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

@caltikoc
Copy link

caltikoc commented Jul 8, 2022

No problem now, you can build your project directly using npx react-native init YourProject.
Happy coding :)

@ItsCDubb
Copy link

ItsCDubb commented Jul 8, 2022

When you use npx react-native init InsertProjectNameHere --version 0.68.2 --template react-native-template-typescript nothing happens exept it fails with RuntimeError: abort(Error: Command failed: yarn add react-native-template-react-native-template-typescript~)

how do you get around that? Because I want to use TypeScript not JavaScript

@benjamineruvieru
Copy link

/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).

So after uninstalling what are we to do next?
Are we to reinstall globally again or we dont install globally this time or we dont install at all and give up
Your answer is not complete

@Keyur-RV
Copy link

Keyur-RV commented Jul 11, 2022

@benjamineruvieru After uninstalling, reinstall globally and then create a project, it can be created successfully.
see below picture react-native version is "0.69.1".
Node version is "18.0.0".
Screenshot 2022-07-11 at 10 15 27 AM

@emorilebo
Copy link

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.

@ItsCDubb
Copy link

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

@Dev-Vithushan
Copy link

Dev-Vithushan commented Jul 22, 2022

I am using MacOS 12.4 and for me When i was created the React Native app using npm it is showing like this
I used cli 0.68.2

Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command. Error: Command failed: yarn add react-native@0.68.2 --exact at checkExecSyncError (child_process.js:790:11) at execSync (child_process.js:863:15) at run (/Users/vithushan/.config/yarn/global/node_modules/react-native-cli/index.js:294:5) at createProject (/Users/vithushan/.config/yarn/global/node_modules/react-native-cli/index.js:249:3) at init (/Users/vithushan/.config/yarn/global/node_modules/react-native-cli/index.js:200:5) at Object.<anonymous> (/Users/vithushan/.config/yarn/global/node_modules/react-native-cli/index.js:153:7) at Module._compile (internal/modules/cjs/loader.js:1085:14) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10) at Module.load (internal/modules/cjs/loader.js:950:32) at Function.Module._load (internal/modules/cjs/loader.js:790:12) { status: 1, signal: null, output: [ null, null, null ], pid: 36901, stdout: null, stderr: null } Command yarn add react-native@0.68.2 --exact failed.

Give me a solution!!!

@Bsingh2697
Copy link

Bsingh2697 commented Jul 22, 2022 via email

@jalloh-codes
Copy link

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.

This works for me, thanks @emorilebo

@dmcchanaka
Copy link

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

@Bikash9609
Copy link

/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).

Worked for me too. Thanks!

@zainulabideen-dev
Copy link

I just run below command and it works for me
npx react-native init StudentsHub --version 0.69.1

@zainulabideen-dev
Copy link

zainulabideen-dev commented Aug 31, 2022 via email

@ansarikhurshid786
Copy link

I fixed by deleting folder:
(/Users/user/.config/yarn/global/node_modules/react-native-cli

Now it is working for me. I think it is old which is completely not deleted.

@pistolcaffe
Copy link

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)

@kevinsiregar22
Copy link

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

@alexeenka
Copy link

26 Dec. I have the same error:

/Users/a.alexeenka/.nvm/versions/node/v19.3.0/lib/node_modules/react-native-cli/index.js:302
  cli.init(root, projectName);
      ^

TypeError: cli.init is not a function

Only running with 'react-native init MyApp --version 0.68.2' fixed the issue

@msriaz
Copy link

msriaz commented Dec 28, 2022

Surprisingly none of above worked for me other than:

yarn remove react-native -g
yarn remove react-native-cli -g

Please also make sure you've correct version of ruby
React Native uses this version of Ruby. You can also find which version your specific project needs in the .ruby-version file at root of your RN project

@ghost
Copy link

ghost commented Jan 31, 2023

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

It's do as ran as administrator mode ??

@Serendipity-hope
Copy link

npx react-native@X.XX.X init project--version X.XX.X
npx react-native@0.72.0 init AwesomeProject --version 0.72.0

@horaczech
Copy link

I got it working after going to /Users/{{username}}/node_modules (using Mac), and manually removed folders "react-native", "react-native-cli", "@react-native"

@azizimusa
Copy link

npm uninstall -g react-native-cli

thanks. This also work with WebStorm new react native project

npx --package react-native-cli react-native --version 0.68.2

Then inside project. Update manually from package.json, then run npm install on terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impact: Misconfiguration When the issue is due to a misconfig for the user Platform: macOS Building on macOS. Resolution: Answered When the issue is resolved with a simple answer
Projects
None yet
Development

No branches or pull requests