Home > Mobile >  Cannot add Firestore to Expo-managed project
Cannot add Firestore to Expo-managed project

Time:08-16

I am working on an app that was running fine however, when I tried to add firestore it crashes. I followed all the official documentation from Google and Expo as well, but as soon as I add the initializeApp import it throws me the error. It happens in both Android and iOS. I even removed the code to isolate the problem so the js file has next to nothing and it keeps crasing.

import React, {useState, useEffect, Component} from 'react';
import { StyleSheet, Text, View, TouchableOpacity, FlatList, SafeAreaView, Pressable, RefreshControl, StatusBar, ActivityIndicator } from 'react-native';
import { initializeApp } from 'firebase/app';

const HomeScreen = () => {

    return(<Text>Home Screen</Text>)

}
export default HomeScreen;

Here's the error

Android Bundling failed 6363ms
While trying to resolve module `idb` from file `/Users/noisemastering/Apps/Cartelera/node_modules/@firebase/app/dist/esm/index.esm2017.js`, the package `/Users/noisemastering/Apps/Cartelera/node_modules/idb/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/noisemastering/Apps/Cartelera/node_modules/idb/build/index.cjs`. Indeed, none of these files exist:

  * /Users/noisemastering/Apps/Cartelera/node_modules/idb/build/index.cjs(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
  * /Users/noisemastering/Apps/Cartelera/node_modules/idb/build/index.cjs/index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)

CodePudding user response:

create a metro.config.js file in your project. this file will contain:

const { getDefaultConfig } = require("@expo/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

defaultConfig.resolver.assetExts.push("cjs");

module.exports = defaultConfig;
  • Related