Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Problem: TypeError: cli.

init is not a function

This problem occurs when the globally installed packages react-native and
react-native-cli are outdated, as mentioned here.

However, the issue does not seem to be resolved when instantiating a new React
Native project through IntelliJ IDEA or IntelliJ Brainstorm. The solution to this would
be to run the below command while creating a new project.

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

This solution works but is not recommended as the latest React Native version
currently is 0.73.6 and the effort required to upgrade to the latest version is quite
high.

The changes required to upgrade RN from 0.68.2 to 0.73.6 can be found here.

Please follow the below steps, to successfully create and run a RN project in IntelliJ
IDEA.
Creating a new React Native project in IntelliJ IDEA:

1. Click on File -> New -> Project or Click on New Project button on the welcome
screen
2. Provide a name for your new RN project
3. Select React Native button in the Project Type field
4. In the React Native text field, modify the command to npx --package
@react-native-community/cli react-native
5. Click on Create button

The new RN project should be successfully created. Select the


Android run config from the dropdown at the top of the window
and click on the Run Android button next to it to build the
project and run the app on the Android emulator.
Creating a New Project from my git repository
1. Click on File -> New -> Project from Version Control or click on Get from VCS
button on the welcome screen
2. Select Git from the Version Control dropdown
3. Paste the following URL: https://github.com/harkej/rn-hello-world
4. Click on clone to setup the project in your local machine
5. Run yarn install in the terminal or click on Run ‘yarn
install’ option in the IDE notification popup
6. Click the current file dropdown and select Edit
configurations… option
7. In the left pane, click on Add new... option and select
React Native from the list of configurations

8. Name it as Android and make sure the Build and Launch


option is checked, Platform is selected as Android, and
Hermes engine is enabled is checked

9. Click on Apply or OK to save the configuration.


10. Click on the Run ‘Android’ button on top of the window
to run the project in your emulator

You might also like