15

This is my first app. I'm trying to use Firebase for Email/Password authentication. I followed the basic tutorial https://firebase.google.com/docs/auth/web/password-auth#web-version-9, and I keep getting this error:

While trying to resolve module `idb` from file '.../node_modules/@firebase/app/dist/esm/index.esm2017.js', the package `/Users/##/##/##/node_modules/idb/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/##/##/##/node_modules/idb/build/index.cjs`. 

I've added this to metro.config.js:

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

and the issue is still there.

KrishP
  • 165
  • 1
  • 6

2 Answers2

27

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;

ScreenShot

Sohel Islam Imran
  • 1,631
  • 6
  • 10
6

I get the same error when adding firebase to a clean project. I think there's something funny with the latest firebase version so I've downgraded to 9.6.11 to temporarily fix the problem. Hopefully they sort it out soon...

npm uninstall firebase
npm install firebase@9.6.11
crunchytoast
  • 488
  • 4
  • 5