TypeError: cli.init is not a function in React Native

avatar
Borislav Hadzhiev

Last updated: Apr 7, 2024
2 min

banner

# TypeError: cli.init is not a function in React Native

The error "TypeError: cli.init is not a function" occurs when you have an outdated, globally installed version of the React native CLI.

To solve the error, uninstall the globally installed version of the package and use the npx react-native init AwesomeProject command instead.

shell
TypeError: cli.init is not a function at run (/Users/bobbyhadz/.config/yarn/global/node_modules/react-native-cli/index.js:302:7) at createProject (/Users/bobbyhadz/.config/yarn/global/node_modules/react-native-cli/index.js:249:3)

# Update your version of the react-native-cli

Open your terminal and make sure you don't have a globally installed version of the react-native-cli installed.

shell
# ๐Ÿ‘‡๏ธ NPM - Uninstall the React native CLI globally npm uninstall -g react-native-cli @react-native-community/cli react-native npm -g list # ๐Ÿ‘‡๏ธ YARN - Uninstall the React native CLI globally yarn global remove react-native-cli @react-native-community/cli react-native yarn global list

uninstall react native cli

If you get a permissions error when uninstalling the CLI, prefix the command with sudo (macOS and Linux) or open CMD as an administrator and rerun the command (Windows).

You shouldn't see a global version of the react native CLI installed when you issue the npm -g list command.

shell
npm -g list

verify react native uninstalled globally

Once the React native CLI has been uninstalled, issue the following command to create a new project.

shell
# ๐Ÿ‘‡๏ธ Create a new React Native project called "AwesomeProject" npx react-native init AwesomeProject # ๐Ÿ‘‡๏ธ Create a new TypeScript-based React Native project npx react-native init AwesomeTSProject --template react-native-template-typescript

If you use TypeScript, issue the second command in your terminal.

# Using npx instead of a global install

If you use the npx prefix, without installing react-native globally (which is the recommended approach), you would have to prefix any react-native command with npx.

shell
npx react-native start npx react-native run-android

If the error persists, try to run the react-native init command scoped to version 0.68.2.

shell
npx react-native init AwesomeProject --version 0.68.2 # ๐Ÿ‘‡๏ธ For TypeScript projects npx react-native init AwesomeTSProject --template react-native-template-typescript --version 0.68.2

# Installing react-native globally

If you still want to install react-native globally to be able to use the command without the npx prefix, run the following command.

Note that installing react-native globally is not recommended. The recommended approach is to use npx react-native without having the package globally installed.
shell
# ๐Ÿ‘‡๏ธ If you use NPM npm install -g react-native npm install -g react-native-cli # ๐Ÿ‘‡๏ธ If you use YARN yarn global add react-native yarn global add react-native-cli # ๐Ÿ‘‡๏ธ Create a React Native project npx react-native init AwesomeProject # ๐Ÿ‘‡๏ธ Create a new TypeScript-based React Native project npx react-native init AwesomeTSProject --template react-native-template-typescript

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev