Problem adding Firebase to Creator 3.0

I have a problem adding Firebase SDK to Cocos Creator 3.0. After installing with yarn add firebase@7.23.0 and created a script below

import * as firebase from 'firebase/app';
const app = firebase.app();

I got an error ‘Failed to load module’ (in Cocos 2.4, it works fine) Anyone knows how to fix this?

There are currently problems with engine compatibility with this library, so I would suggest that Firebase be packaged as a single file and then set up as a plugin script to run.

https://docs.cocos.com/creator/3.0/manual/en/scripting/external-scripts.html

Does this mean Creator 3 won’t support packages from NPM?

It should Tutorial: How To Flexibly Use The Huge Amount Of npm Resources In Cocos Creator 3.0

Thank you for pointing me to the tutorial. It is very well-written. I have followed lodash-es use case and been able to import the package successfully. However, I got stuck with jsonwebtoken package.

If I just yarn install jsonwebtoken, there will be errors about stream package

image

so, I yarn install stream in order to fix them, I get into other errors

image

It seems packages in node_modules tried to resolve dependency by looking at CocosDashboard folder

Is there any workaround for this?

Please try the following:

import firebase from 'firebase/firebase-app.js'; // Use the browser edition

image

The reason and the solution to the typing problem can be found in this thread.

Thank you very much. Now I can import firebase-app with its types. However, when I continued to import firebase-firestore.js, I got into these errors

image

Looking into firebase-firestore.js, it has references to dom-storage and xml-http-request and those two modules require node packages i.e. fs, http. I assume this is the source of the errors

Is there a way to get around?

What platform are you targeting ? If it’s native platforms, you should not use npm firebase, you should be using firebase native SDK

Hi. It’s web platform I am targeting

Then the dependencies should be packed too, I’m not sure how to do it @shrinktofit

Looking into firebase-firestore.js, it has references to dom-storage and xml-http-request and those two modules require node packages i.e. fs, http. I assume this is the source of the errors

Yes. It’s staticly analyzed to reference those Node modules. But it should be allowed since in code it will do a runtime test.

I’ll try to fix this limit. But it won’t be earlier than 3.2 maybe. As a workaround, you may try to bundle the required modules using external bundler and put the single file into Creator.

This is the Cloud Firestore component of the Firebase JS SDK.

This package is not intended for direct usage, and should only be used via the officially supported firebase package.

Comming from: firebase-js-sdk/packages/firestore at master · firebase/firebase-js-sdk (github.com)