[Fix] IOS Bundling failed

The Error “IOS Bundling failed”, is an error that is invoked when you are working on react-native and are using firebase in your project. Given below is the snippet of the error you might get:

IOS Bundling failed

Here is the snapshot of the error you might get of the error:

I would like to share with you the steps I took to fix the “IOS Bundling failed”

Why “IOS Bundling failed” Error is Seen?

The error, “IOS Bundling failed” is seen because Firebase uses the.cjs file extension, which is not by default supported by expo or react native. Therefore, you must manually set up Metro.config to parse it.

The error IOS Bundling failed is also caused because of the firebase version. You have to downgrade your firebase version to version 9.6.11 to fix the issue temporarily.

The detailed solution to fix the error “IOS Bundling failed”, is given below:

How to fix “IOS Bundling failed” Error?

To fix the error, “IOS Bundling failed”, you need to manually set up Metro.config to parse it or you will have to downgrade your firebase version to version 9.6.11 to fix the issue.

Follow the below mentioned steps to fix the “IOS Bundling failed” error:

Firebase uses the.cjs file extension, which is not by default supported by expo or react native. Therefore, you must manually set up Metro.config to parse it.

To fix this problem if you are using expo, create a metro.config.js file in the project root.

Add the cjs file extension to the document, by following the below mentioned code example:

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

const defaultConfig = getDefaultConfig(__dirname);

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

module.exports = defaultConfig;

For the React Native cli follow the below mentioned code example:

const { getDefaultConfig } = require("metro-config");
const { resolver: defaultResolver } = getDefaultConfig.getDefaultValues();
exports.resolver = {
  ...defaultResolver,
  sourceExts: [
    ...defaultResolver.sourceExts,
    "cjs",
  ],
};

In case you are still facing the same problem then it is likely that the issue is with you firebase version.

Therefore you will have to downgrade your firebase version to version 9.6.11 to fix the issue temporarily. You can do so by following the below mentioned code:

npm uninstall firebase
npm install firebase@9.6.11

This should fix the error “IOS Bundling failed”.

Conclusion

To fix the error, “IOS Bundling failed” , you must manually set up Metro.config to parse it. If this does not work then you will have to downgrade your firebase version to version 9.6.11 to fix the issue temporarily.