TypeScript import statement cannot find Firebase module in Expo project

Viewed 392

I'm starting a brand new Expo project and following all docs as published on August 28, 2021. The import statement specified by the Firebase docs does not work. Here are the steps to reproduce.

expo init firebase-demo

Select blank (TypeScript) and hit enter.

cd firebase-demo
expo install firebase

Add this line to App.tsx, as the docs say:

import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";

And you get this error: Module '"firebase/auth"' has no exported member 'getAuth'.

A clue as to what's going wrong is that in VS Code, if I command-click on "firebase/auth" it opens node_modules/firebase/empty-import.d.ts whose entire content is:

declare namespace empty {}
export = empty;

There is a node_modules/firebase/auth directory. Why isn't the import statement finding that?

Here's my tsconfig.json, which I have not modified from what expo init created:

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "strict": true
  }
}
2 Answers

I faced the same problem. My solution is:

add: "exclude": ["node_modules", "node_modules/**/*"] to your jsconfig.json and then Ctrl+Shift+P -> Reload window

Another solution I ran into:

do the same, but delete node_modules folder from your project before editing jsconfig.json and run npm install right after Ctrl+Shift+P -> Reload Window

I fixed this by upgrading firebase to 9.0.0. The problem seems to be caused by the fact that expo install firebase installed quite an old version - 8.2.3, from 7 months ago. The current version is 9.0.0, and the current documentation is presumably for that. I'm going to proceed with caution because 9.0.0 isn't certified for use with Expo. (I guess another possible solution would be to find the documentation for 8.2.3).

Related