1
votes

I am attempting the latest Firebase npm module (4.8.1). I am using the commonjs module system with webpack bundling. In order to ensure I'm getting the typings I need I have the following in my package.json:

"dependencies: {
  "firebase": "^4.8.1"
},
"devDependencies": {
  "@firebase/app": "^0.1.5",
  "@firebase/app-types": "^0.1.0",
  "@firebase/auth": "^0.3.1",
  "@firebase/auth-types": "^0.1.0",
  "@firebase/database": "^0.1.6",
  "@firebase/database-types": "0.1.0",
}

When I transpile with tsc I get the following errors:

node_modules/@firebase/database/dist/esm/src/api/Database.d.ts(4,33): error TS2307: Cannot find module '@firebase/app-types/private'.

node_modules/@firebase/database/dist/esm/src/core/AuthTokenProvider.d.ts(17,39): error TS2307: Cannot find module '@firebase/app-types/private'.

I find this VERY odd for several reasons:

  1. I am using CommonJS module system not ESM
  2. I have assumed that the @firebase/data-types is there to provide typings rather than implementation code. That's why I have it listed as as devDependency instead of dependency
  3. Even if I switch all the @firebase/* to "dependencies" it still gives same error
  4. I did see other people post here that Firebase 4.8.1 has an error in it and that rolling back to 4.8.0 might fix the problem ... but from what I can see 4.8.0 has all sort of "implicit any" errors (which maybe I could justify turning off) but also lots of other deprecations in the API that is exported. Simply put, it appears to me that 4.8.1 is much better as typings reference.
1

1 Answers

1
votes

With the following tsconfig.jsonit works fine for me:

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs",
    "moduleResolution": "node",
    "inlineSourceMap": true
  }
}

In src/index.ts I just import like this:

// This import loads the firebase namespace along with all its type information.
import * as firebase from 'firebase';

const firebaseApp = firebase.initializeApp({
  apiKey: '<your-api-key>',
  authDomain: '<your-auth-domain>',
  databaseURL: '<your-database-url>',
  storageBucket: '<your-storage-bucket>',
  messagingSenderId: '<your-sender-id>'
});

Before I modified my tsconfig.json I had similar issue with:

{
...
  "devDependencies": {
    ...
  },
  "dependencies": {
    ...,
    "firebase": "^4.8.1"
  }
}

I hope that helps!