TypeError: cli.init is not a function。 React-Native创建新项目时的错误解决方法。

最近在玩React-Native的时候,创建项目出现cli.ini错误,找了好久才知道这个方法,分享给大家。

TypeError: cli.init is not a function – Code Example

From V0.69, React-Native stopped supporting global installation of react-native-cli. If you try to run npx react-native init MyProject command, it will throw TypeError: cli.init is not a function error. To resolve this issue, you need to initialize your project with specific react-native version.

Solution with Code Example

npx react-native init MyProject --version 0.68.2

This will initialize your project on version 0.68.2.

If you want to use the latest cli version, then first you will need to uninstall any globally installed react-native or react-native-cli using this –

执行下面的四个命令:

yarn global remove react-native
 
yarn global remove react-native-cli
 
npm uninstall -g react-native
 
npm uninstall -g react-native-cli

Then, there is no need to install anything. Just use npx like this –

无需再安装React,直接执行下面的命令创建项目:

npx react-native init MyProject
 
 
posted @ 2023-09-26 15:21  商君治国安邦之张莽  阅读(460)  评论(0编辑  收藏  举报