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
# 👇️ 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
sudo (macOS and Linux) or open CMD as an administrator and rerun the
You shouldn't see a global version of the react native CLI installed when you
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.
npxinstead 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
npx react-native start npx react-native run-android
If the error persists, try to run the
react-native init command scoped to
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-nativeglobally is not recommended. The recommended approach is to use
npx react-nativewithout 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: