简体   繁体   English

React Native 构建失败

[英]React Native Building failed

I have a project built with Expo.我有一个用 Expo 构建的项目。 I am using Firebase for google authentication and Firestore to save the data.我正在使用 Firebase 进行 google 身份验证,并使用 Firestore 来保存数据。 When I am running the app using expo start after I run the app on my emulator I am getting the following error:当我在模拟器上运行应用程序后使用expo start运行应用程序时,出现以下错误:

在此处输入图像描述

I tried running yarn install and try running the expo server again but the same result.我尝试运行yarn install并再次尝试运行 expo 服务器,但结果相同。 Any idea what is causing this issue?知道是什么导致了这个问题吗?

Regarding the issue, I found this documentation that will help you with your React Native project with Firebase .关于这个问题,我发现这个文档可以帮助您使用Firebase进行React Native项目。

You should create a metro.config.js file in the project root if you're using expo to address this problem.如果你使用 expo 来解决这个问题,你应该在项目根目录中创建一个metro.config.js文件。 Add the cjs file extension to the file.将 cjs 文件扩展名添加到文件中。

More file extensions that are considered an asset are being added to metro.config.js.更多被视为资产的文件扩展名被添加到 metro.config.js。 By default, many image, video, audio, and font formats (such as jpg, png, mp4, mp3, and ttf) are included.默认情况下,包括许多图像、视频、音频和字体格式(例如 jpg、png、mp4、mp3 和 ttf)。 Create a metro.config.js file in the project root to add new asset file extensions.在项目根目录中创建一个 metro.config.js 文件以添加新的资产文件扩展名。

const { getDefaultConfig } = require('@expo/metro-config'); const defaultConfig = getDefaultConfig(__dirname); defaultConfig.resolver.assetExts.push('db'); module.exports = defaultConfig;

Code Example:代码示例:

module.exports = { 
  transformer: { 
    getTransformOptions: async () => ({ 
      transform: { 
        experimentalImportSupport: false, 
        inlineRequires: true, 
      }, 
    }), 
   }, 
//added this 

 resolver: { 
    sourceExts: ['jsx', 'js', 'ts', 'tsx', 'cjs'], 
  }, 
};

As an alternative solution, it appears that the most recent version has various flaws.作为替代解决方案,最新版本似乎存在各种缺陷。 All you have to do now is downgrade to firebase@9.6.11 .您现在要做的就是降级到firebase@9.6.11 Primarily, use this command to uninstall the Firebase package.首先,使用此命令卸载 Firebase 软件包。

npm uninstall firebase

Now, execute this command to install Firebase 9.6.11.现在,执行此命令以安装 Firebase 9.6.11。

npm install firebase@9.6.11

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM