TypeError:cli.init不是React Native的功能

发布于 2025-02-10 17:37:46 字数 812 浏览 5 评论 0 原文

MacBook Air M1芯片中运行NPX React-NIT INIT APPNAME时

TypeError: cli.init is not a function
at run (/opt/homebrew/lib/node_modules/react-native-cli/index.js:302:7)
at createProject (/opt/homebrew/lib/node_modules/react-native-cli/index.js:249:3)
at init (/opt/homebrew/lib/node_modules/react-native-cli/index.js:200:5)
at Object.<anonymous> (/opt/homebrew/lib/node_modules/react-native-cli/index.js:153:7)
at Module._compile (node:internal/modules/cjs/loader:1112:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:834:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47

While running npx react-native init appName in MacBook air M1 chip

TypeError: cli.init is not a function
at run (/opt/homebrew/lib/node_modules/react-native-cli/index.js:302:7)
at createProject (/opt/homebrew/lib/node_modules/react-native-cli/index.js:249:3)
at init (/opt/homebrew/lib/node_modules/react-native-cli/index.js:200:5)
at Object.<anonymous> (/opt/homebrew/lib/node_modules/react-native-cli/index.js:153:7)
at Module._compile (node:internal/modules/cjs/loader:1112:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:834:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(20

傲世九天 2025-02-17 17:37:47

如果您以前安装了全局React-Native-CLI软件包,请删除它,因为它可能会导致意外问题。 You can run the following command:

npm uninstall -g react-native-cli @react-native-community/cli

or

yarn global remove react-native-cli @react-native-community/cli

Follow the Reference: https://reactnative.dev/docs/environment-设置

if you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues. You can run the following command:

npm uninstall -g react-native-cli @react-native-community/cli

or

yarn global remove react-native-cli @react-native-community/cli

Follow the Reference: https://reactnative.dev/docs/environment-setup

北斗星光 2025-02-17 17:37:47

我尝试了上面提到的所有解决方案,除此之外,它们实际上没有工作(NPX React-Nitation Init ProjectName - Version 0.68.2),

但最后我通过从用户文件夹中删除节点模块来解决问题。

现在运行:-npx react-native@最新init projectname

I tried every solution above mentioned none of them didn't worked actually except this(npx react-native init ProjectName --version 0.68.2)

But finally i fixed my issue by deleting node modules from my user folder .Go to user/username/and delete node modules and old projects or any package.json files.

then now run :- npx react-native@latest init projectname

你丑哭了我 2025-02-17 17:37:47

npx反应本地启动aveyproject-version 0.68.2解决了我的问题

npx react-native init AwesomeProject --version 0.68.2 solved my problem

归属感 2025-02-17 17:37:47

我不记得我用啤酒安装了它,这就是问题所在,必须从那里删除它,也必须

首先卸载:

  BREW删除React-Native-CLI
NPM卸载-g反应-GLI
NPM卸载-g反应本
 

下一步,安装:

  npm install -g react -native
NPM安装-G反应-CLI
 

I didn't remember that I installed it with brew and that was the problem, it must be deleted from there as well

First uninstall:

brew remove react-native-cli
npm uninstall -g react-native-cli
npm uninstall -g react-native

Next step, install:

npm install -g react-native
npm install -g react-native-cli
中二柚 2025-02-17 17:37:47

使用此命令删除React本地CLI

npm卸载-g反应-g
然后
NPM安装-G反应

现在无需它。

React Native具有内置命令行接口,您可以使用该界面来生成一个新项目。

检查 reactnative.dev

remove react native cli using this command

npm uninstall -g react-native-cli
then
npm install -g react-native

no need for it now as.

React Native has a built-in command line interface, which you can use to generate a new project.

Check reactnative.dev

鹿童谣 2025-02-17 17:37:47

尝试使用此最新命令。

npx react-native@latest init ProjectName

为我工作!

Try with this latest command.

npx react-native@latest init ProjectName

Worked for me!

嘿看小鸭子会跑 2025-02-17 17:37:46

安装新的反应局全球

npm uninstall -g react-native-cli

安装新的反应本地全局

npm install -g react-native-cli

npm install -g react-native

,然后再次创建项目

npx react-native init AwesomeProject

install new react-native global

npm uninstall -g react-native-cli

install new react-native global

npm install -g react-native-cli

npm install -g react-native

and create project again

npx react-native init AwesomeProject
苏辞 2025-02-17 17:37:46

需要使用以下命令来清洁全局环境:

yarn global remove react-native

yarn global remove react-native-cli

npm uninstall -g react-native

npm uninstall -g react-native-cli

检查与这些列表中的反应态礼物没有任何关系:

yarn global list

npm -g list

安装新的反应局全局,

npm install -g react-native-cli
npm install -g react-native

然后您可以运行:

npx react-native init ProjectName 

Need to clean global environments with following commands:

yarn global remove react-native

yarn global remove react-native-cli

npm uninstall -g react-native

npm uninstall -g react-native-cli

check that nothing related to react-native presents in these lists:

yarn global list

npm -g list

install new react-native global

npm install -g react-native-cli
npm install -g react-native

then you can run:

npx react-native init ProjectName 
安静被遗忘 2025-02-17 17:37:46

这发生了,因为您有一个旧版本的反应本机,所以
需要在全球范围内删除React Native版本并再次安装。

解决问题的步骤:

如果使用纱线:

第一步:
检查全局安装列表:

yarn global list

如果您发现了反应和反应型CLI,请转到下一步
并将它们删除在全球范围内

yarn global remove react-native
yarn global remove react-native-cli

第三步:
第一步

yarn global add react-native
yarn global add react-native-cli

如果使用NPM:


检查全局安装列表:

npm -g list

如果您发现了反应和反应型CLI,请转到下一步
并将它们删除在全球范围内

npm uninstall -g react-native
npm uninstall -g react-native-cli

第三步:
再次安装

npm install -g react-native
npm install -g react-native-cli

注意:删除您创建的旧项目,然后再次创建它。每一个
事情会很好。

This happened because you have an old version of react native, So you
need to remove the react native version globally and install it again.

Steps to fix your problem:

if you use Yarn:

First Step:
Check the Global installation list:

yarn global list

if you found react-native and react-native-cli so go to the next step
and remove them globally

Second Step:

yarn global remove react-native
yarn global remove react-native-cli

Third Step:
Install them again

yarn global add react-native
yarn global add react-native-cli

if you use NPM:

First Step:
Check the Global installation list:

npm -g list

if you found react-native and react-native-cli so go to the next step
and remove them globally

Second Step:

npm uninstall -g react-native
npm uninstall -g react-native-cli

Third Step:
Install them again

npm install -g react-native
npm install -g react-native-cli

Note: Delete the old project you create, then create it again. Every
thing will go fine.

帥小哥 2025-02-17 17:37:46

这就是错误来自新版本0.69.0
您可以使用 npx React-nitation Init ProjectName - Version 0.68.2 ,然后升至V 0.69。

That is error is from the new version 0.69.0
You can use npx react-native init ProjectName --version 0.68.2 and then upgrade to v 0.69 later.

仲春光 2025-02-17 17:37:46

如果您以前安装了全局react-native-cli软件包,请删除它,因为它可能会引起意外问题:

npm卸载-G react-native-cli @react-native-native-cli @react-native-cli-compontity/cli

react react Antial内置命令行界面,您可以用来生成一个新项目。您可以在不使用NPX上安装所有内容的情况下访问它,该npx用node.js寄出。让我们创建一个名为“ AwesomeProject”的新的React Native项目:

npx React-native@最新init akesteyproject

如果您将React Antive集成到现有应用程序中,那么如果您从Expo中“弹出”,则无需或者,如果您将Android支持添加到现有的React Native项目(请参阅与现有应用程序集成)。您也可以使用第三方CLI来启动您的React本机应用程序,例如Ignite CLI。

If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues:

npm uninstall -g react-native-cli @react-native-community/cli

React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using npx, which ships with Node.js. Let's create a new React Native project called "AwesomeProject":

npx react-native@latest init AwesomeProject

This is not necessary if you are integrating React Native into an existing application, if you "ejected" from Expo, or if you're adding Android support to an existing React Native project (see Integration with Existing Apps). You can also use a third-party CLI to init your React Native app, such as Ignite CLI.

冷月断魂刀 2025-02-17 17:37:46

如果您以前安装了全局React-native-CLI软件包,请删除它,因为它可能会引起意外问题:

npm uninstall -g react-native-cli @react-native-community/cli

链接

If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues:

npm uninstall -g react-native-cli @react-native-community/cli

Link Here

爱殇璃 2025-02-17 17:37:46

我认为最新的稳定版本为0.68.2,因此在此级别上创建项目,使用下面给出的命令

npx react-nib init project projectName-version 0.68.2

I think latest stable version is 0.68.2, so create project at this level using command given below

npx react-native init ProjectName --version 0.68.2

街角迷惘 2025-02-17 17:37:46

应运行:

纱线全局列表 npm全局列表

并卸载了列表中的所有cli at react-nvent in List:

yarn global add @react-native-community/cli

Should run:

yarn global list or npm global list

And uninstall all cli's of the react-native in list, after run:

yarn global add @react-native-community/cli
失眠症患者 2025-02-17 17:37:46
yarn add react-native --exact

我重新安装了与 - 外部的反应本机,这解决了我的问题

yarn add react-native --exact

I re-installed react native with --exact and this fixed my problem

仙女 2025-02-17 17:37:46

在命令提示中,

  1. 卸载CLI反应本式全局
    代码---&GT; NPM卸载-g反应 - cli

  2. install cli在命令提示中安装CLI
    A.代码==&gt; npm install -g react-native-cli,
    b.code ==&gt; NPM安装-G反应

  3. 最终创建项目,
    code ==&gt; npx react-nibative initakeyproject

In command Prompt,

  1. uninstall cli react-native global
    code---> npm uninstall -g react-native-cli

  2. Install cli in command prompt
    a.code==> npm install -g react-native-cli,
    b.code==> npm install -g react-native

  3. Finally create project,
    code==>npx react-native init AwesomeProject

花开半夏魅人心 2025-02-17 17:37:46

do-&gt;
YARN Global删除React-Native-Cli&amp; amp; NPM卸载-g react-native-cli

然后 - &gt;
纱线全局添加 @react-native-community/cli
或者
NPM安装-G react-native-cli

Do->
yarn global remove react-native-cli && npm uninstall -g react-native-cli

Then->
yarn global add @react-native-community/cli
or
npm install -g react-native-cli

情感失落者 2025-02-17 17:37:46

我能够通过卸载CLI来清除问题,并且只安装反应,

npm uninstall -g react-native-cli
npm install -g react-native

然后

react-native init ProjectName

我正在使用

react-native -v
10.1.3

I was able to clear the issue by uninstalling the cli and only installing react-native

npm uninstall -g react-native-cli
npm install -g react-native

then

react-native init ProjectName

I am using

react-native -v
10.1.3
〃温暖了心ぐ 2025-02-17 17:37:46

如果您已经安装了全球对本地的反应,请通过以下方式卸载它:
NPM卸载-G react-native-cli

然后通过:
npm install -G react-native-cli

然后您可以通过以下命令创建新项目:
NPX React-native Init&lt; project_name&gt; gt;

If you have already installed react native globally, uninstall it by:
npm uninstall -g react-native-cli

Then install it again by:
npm install -g react-native-cli

Then you can create your new project by the following command:
npx react-native init <project_name>

奶气 2025-02-17 17:37:46

来自 - &gt; https://reactnative.dev/docs/getting-started-without-a-框架

如果您以前安装了全局react-native-cli软件包,请删除它,因为它可能会引起意外问题:

npm unstall -G react-native-cli @react- react-本地社区/CLI

您可以使用React Native Community CLI来生成一个新项目。让我们创建一个名为“ AwesomeProject”的新React本机项目:

npx @react-native-community/cli @最新init awith awith aviraveproject

FROM -> https://reactnative.dev/docs/getting-started-without-a-framework

If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues:

npm uninstall -g react-native-cli @react-native-community/cli

You can use React Native Community CLI to generate a new project. Let's create a new React Native project called "AwesomeProject":

npx @react-native-community/cli@latest init AwesomeProject

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文