ReactNative:未被捕获的TypeError:构建KitchenSink演示时,无法读取未定义的属性'forEach' [英] ReactNative: Uncaught TypeError: Cannot read property 'forEach' of undefined, while building KitchenSink demo

查看:56
本文介绍了ReactNative:未被捕获的TypeError:构建KitchenSink演示时,无法读取未定义的属性'forEach'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为"react-native"编译一个厨房水槽"演示:

I am trying to compile a 'kitchen-sink' demo, for 'react-native':

NativeBase-KitchenSink

,并且我已经关注了以下链接:

, and I have followed the following links already:

反应原生:未找到Android项目.也许首先运行react-native android?"的解决方案

"Expo:找不到模块LogReporter"解决方案

也就是说,从安装'npm'到使用'纱线'安装必需的工具.

That is, from the installation of 'npm' till the installation of required tools using 'Yarn'.

现在我被困住了自己

a.我在该项目的根目录"中运行命令 npm install .

a. I run the command npm install in the 'root directory' of this project.

b.然后运行 expo start ,我发现链接1和2中解决的问题已经消失.

b. Then I run expo start, I see that the problems addressed in link 1 and 2 have gone away.

c.然后,当浏览器启动时,我发出 expo build:android

c. Then when the browser is up, I issue expo build:android

出现以下错误:

[11:14:44] Checking if current build exists...
[11:14:48] No currently active or previous builds for this project.
[11:14:50] Publishing to channel 'default'...
[11:14:56] Building iOS bundle
[11:15:09] Building Android bundle
[11:15:20] Analyzing assets
[11:15:27] Uploading assets
[11:15:27] No assets to upload, skipped.
[11:15:27] Processing asset bundle patterns:
[11:15:27] - D:\Projects\ReactNativeProjects\AwesomeProject\**\*
[11:15:27] Cannot read property 'forEach' of undefined
[11:15:27] TypeError: Cannot read property 'forEach' of undefined
at C:\xdl@51.4.0\src\Project.js:903:26
at Generator.next (<anonymous>)
at step (C:\Users\hp\AppData\Roaming\npm\node_modules\expo-cli\node_modules\xdl\build\Project.js:2033:191)
at C:\Users\hp\AppData\Roaming\npm\node_modules\expo-cli\node_modules\xdl\build\Project.js:2033:361

请帮助我知道我哪里错了?一些帖子说代码是正确的.

Please help me know where I am wrong? Some posts say the code is correct.

:

在执行命令 react-native弹出创建Android和iOS文件夹之前,我还在'app.json'中做了新操作:

I also did a new thing in my 'app.json', just before executing command react-native eject, to create Android and iOS folders:

(注意:发出 react-nativeject 命令不是强制性的,因为这会导致永久更改,根据文档)

(Note: It is not mandatory to issue the react-native eject command, as this will cause permanent change according to the documentations)

{
  "expo": {
    "name": "AwesomeProject",
    "description": "A Kitchen Sink project.",
    "slug": "AwesomeProject",
    "privacy": "public",
    "sdkVersion": "30.0.0",
    "platforms": [
      "ios",
      "android"
    ],
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "package": "com.abhsax.first"
    },
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/logo.png",
    "splash": {
      "image": "./assets/splashscreen.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ]
  },
"changes": "----below are the changes----",
  "name": "AwesomeProject",
  "displayName": "AwesomeProject"
}

也就是说,刚添加时:

"name": "AwesomeProject",
 "displayName": "AwesomeProject"

位于"app.json"底部

at the bottom of my 'app.json'

命令 react-native弹出开始起作用,由于输出为:

the command react-native eject started working, which was not working earlier, as the output was:

必须在 app.json 配置文件中定义

App 名称,才能定义项目名.它不能包含任何空格或破折号.

App name must be defined in the app.json config file to define the project name. It must not contain any spaces or dashes.

很明显,它是两种不同版本的程序包管理器的组合:"Expo"和"npm".

Clearly, it is the hybrid of two different versions of the package managers: 'Expo' and 'npm'.

但是这里关注的"forEach"错误并没有消失.

But the 'forEach' error in the concern here, did not go away.

所做的进一步努力没有用,所以我不在这里.

Further efforts done were useless, so I am not putting them here.

我会继续努力直到找到答案.

I shall keep on trying until I figure it out.

推荐答案

我解决了这一问题,因为我再次与软件包管理器混在一起:"npm"和"yarn",这次您不需要"expo"暂时或全部删除,因此请修改您的"app.json",删除"expo"部分.

I resolved this by knowing that I was again mixing up with the package managers: 'npm' and 'yarn', and this time you do not need 'expo' for time being or all-together, so modify your 'app.json', removing expo section.

我要做的就是依次发出以下命令.

All I had to do was to issue the following commands in order.

  1. 添加React Base

纱线添加react-base --save

  1. 安装对等依赖项

任何"npm"软件包中包含的对等项依赖关系都不会自动安装.您的应用程序将不会明确依赖它.

The peer dependencies included from any 'npm' packages does not automatically get installed. Your application will not depend on it explicitly.

反应本地链接

在此演示项目中,缺少一个依赖项:

In the case of this demo project, one dependency was missing:

react-native链接react-native-vector-icons

  1. 开始纱线

纱线开始

  1. 在android设备或模拟器上运行.

react-native run-android

[注意:] 建议安装Java 8而不是更高版本的Java.请参阅:

[Note:] Java 8 is recommended to be installed instead of higher versions of Java. see: What to install? Java 8 or Java 10

我希望能帮上忙.

快乐编码:-)

这篇关于ReactNative:未被捕获的TypeError:构建KitchenSink演示时,无法读取未定义的属性'forEach'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆