TypeError: cli.init 不是使用 ReactNative 的函数

问题描述 投票:0回答:0

我正在尝试在 Macbook Pro M1X 上设置我的 React Native 环境,遵循 https://reactnative.dev/docs/next/environment-setup 但仍然面临问题。

WebStorm 中创建新项目后,我收到此错误:

TypeError: cli.init is not a function
    at run (/Users/mymac1/.npm/_npx/10e3bde211213596/node_modules/react-native-cli/index.js:302:7)
    at createProject (/Users/mymac1/.npm/_npx/10e3bde211213596/node_modules/react-native-cli/index.js:249:3)
    at /Users/mymac1/.npm/_npx/10e3bde211213596/node_modules/react-native-cli/index.js:217:7
    at /Users/mymac1/.npm/_npx/10e3bde211213596/node_modules/prompt/lib/prompt.js:316:32
    at /Users/mymac1/.npm/_npx/10e3bde211213596/node_modules/async/lib/async.js:142:25
    at assembler (/Users/mymac1/.npm/_npx/10e3bde211213596/node_modules/prompt/lib/prompt.js:313:9)
    at /Users/mymac1/.npm/_npx/10e3bde211213596/node_modules/prompt/lib/prompt.js:322:32
    at /Users/mymac1/.npm/_npx/10e3bde211213596/node_modules/prompt/lib/prompt.js:597:5
    at Interface.onLine (/Users/mymac1/.npm/_npx/10e3bde211213596/node_modules/read/lib/read.js:111:5)
    at Interface.emit (node:events:512:28)

我关注并安装了:

  1. 节点和守望者
  2. Xcode + 调整平台中的命令行工具 + 安装 iOS 模拟器
  3. 安装了Ruby gem (CocoaPods),后来根据用户的建议将版本更改为2.7.6

尝试在终端中启动一个 React Native 项目:(在线建议版本/最新版本也有同样的问题)

 npx react-native init mnkn --version 0.68.2

我收到了这个错误:

error Error: Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/next/environment-setup and follow the React Native CLI QuickStart guide for macOS and iOS.
Error: Error: Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/next/environment-setup and follow the React Native CLI 

通过使用“Yarn”在终端中解决了这个问题,使用“yarn add expo”然后

 npx react-native init mnkn --version 0.68.2

工作(在终端)。

在 WebStorm 中同样的错误(即使使用 Yarn)。

我只是从 JavaScript 和 React Native 开始,我的背景只有 Python 和 C。

在网上找不到任何帮助,所以我会很感激一些帮助。

javascript reactjs react-native webstorm apple-m1
© www.soinside.com 2019 - 2024. All rights reserved.