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.
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