Last updated: Apr 7, 2024
Reading timeยท2 min
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.
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)
Open your terminal and make sure you don't have a globally installed version of
the react-native-cli
installed.
# ๐๏ธ 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
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.
npm -g list
Once the React native CLI has been uninstalled, issue the following command to create a new project.
# ๐๏ธ 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.
npx
instead of a global installIf 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
.
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
.
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
If you still want to install react-native
globally to be able to use the
command without the npx
prefix, run the following command.
react-native
globally is not recommended. The recommended approach is to use npx react-native
without having the package globally installed.# ๐๏ธ 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
You can learn more about the related topics by checking out the following tutorials: