Firebase-js-sdk: Can't find variable: document

Created on 18 Aug 2018  路  5Comments  路  Source: firebase/firebase-js-sdk

[REQUIRED] Describe your environment

  • Operating System version: Windows 10 Pro
  • Browser version: React Native (Expo)
  • Firebase SDK version: 5.4.0
  • Firebase Product: firestore

[REQUIRED] Describe the problem

I've been using Firebase and Firestore Web SDK successfully with React Native and Expo. However, after a recent update it broke, producing the error message "Can't find variable: document". I have identified this code as the problem:

export class BrowserPlatform implements Platform {
  readonly base64Available: boolean;

  readonly emptyByteString = '';

  readonly document = document;

  readonly window = window;
 // ...

The declarations for "document" and "window" were added with this commit:
https://github.com/firebase/firebase-js-sdk/commit/2f17ba02a3a139678b849cd53b2199156e5bc6d1#diff-f48b4026a34711ba92518fa9e6d8eaf7R30

Obviously "document" doesn't exist on the React Native / Expo platform. To fix it locally, I simply added a check in the offending class: https://github.com/Bunkerbewohner/firebase-js-sdk/commit/06436255674a6911f270fd98f7325333ed59ea14

I'd appreciate if this or a similar solution makes it into master to fix the problem.

firestore

All 5 comments

Also experiencing this, it's breaking UMD builds for NodeJS targets. :-1:

Glad we have a fix for this already, experiencing the error on react-native.

I wonder when this fix will be released? and how to work around it in the meantime?

@koraytaylan a work around for local development is to manually fix it in ./node_modules/@firebase/firestore/dist/index.cjs.js in line 7298:

var BrowserPlatform = /** @class */ (function () {
    function BrowserPlatform() {
        this.emptyByteString = '';
        this.document = document; // delete this line
        this.window = window; // delete this line
        this.base64Available = typeof atob !== 'undefined';
    }

Note that you can already use the version of Firestore that addresses this problem by installing the staged version of the next release: npm install firebase@next

Was this page helpful?
0 / 5 - 0 ratings