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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通