'firebase-js-sdk v9 doesn't work with react native? Error: While trying to resolve module `idb`
Solution 1:[1]
I downgraded firebase version to v9.6.1 which works fine.
Solution 2:[2]
If you are using expo, to resolve this issue, create a metro.config.js file in the project root. In the file add the file extension cjs
. details
const { getDefaultConfig } = require("@expo/metro-config");
const defaultConfig = getDefaultConfig(__dirname);
defaultConfig.resolver.assetExts.push("cjs");
module.exports = defaultConfig;
React Native cli
const { getDefaultConfig } = require("metro-config");
const { resolver: defaultResolver } = getDefaultConfig.getDefaultValues();
exports.resolver = {
...defaultResolver,
sourceExts: [
...defaultResolver.sourceExts,
"cjs",
],
};
Solution 3:[3]
I just added the following code to metro.config.js file. Im using Firebase v9.8.1 and React Native CLI
module.exports = {
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
}),
},
//added this
resolver: {
sourceExts: ['jsx', 'js', 'ts', 'tsx', 'cjs'],
},
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Otani Shuzo |
Solution 2 | |
Solution 3 | EdEd |