Uncaught SyntaxError: Cannot use import statement outside a module

Hi @Faisal,

So that depends on how you structured your code. Usually that involves exporting a module which is then made a global object for other scripts to call.

If you do that and load the bundle .js to your project, you will be able to call it from any PlayCanvas or other JS script included with your project.

That’s the meaning of attaching them in the window object above:

// Initialize Firebase
window.firebaseModule = {
   app: initializeApp(firebaseConfig),
   analytics: getAnalytics(app)
};

You can then call it like this:

window.firebaseModule.app;
// or even shorter
firebaseModule.app;
firebaseModule.analytics;
1 Like

https://playcanvas.com/editor/scene/1394679

I have setup a demo project with UI button. Here one firebase module is setup with just one console name function. Can you have a look at it and guide what needs to be done to call that function?

Thanks

It looks like you haven’t initialised the firebase app as shown on this step: Add Firebase to your JavaScript project  |  Firebase Documentation

Once that is done, you can expose the app object from Firebase to the window/global scope and use it elsewhere

1 Like

Eg: https://playcanvas.com/project/940252/overview/f-firebase

Great
Thank you very much
Seems like it works.
Thanks