0

I am trying to setup Firebase in Chrome Extension MV3 and the import function is outputting:

Uncaught SyntaxError: Cannot use import statement outside a module

Check my VS Code here

All the solutions on the internet discuss how you would fix it for normal web applications that can include "type"="module" into the tag of the html of the webpage. But with MV3 Chrome Extensions, the background page is now a service worker background.js.

I have also read that there should be a package.json file that indicates to my background.js script that I am importing modules, but I did not reach any useful milestone with this information.

Mike Harb
  • 93
  • 1
  • 9
  • Note that you can't use remote code in a ManifestV3 extension. AFAIK Firebase is not compatible with MV3 service worker so you'll have to use it in a separate visible tab that the user shouldn't close. – wOxxOm Sep 28 '21 at 21:08
  • @wOxxOm Thank you for pinpointing the post, I updated Google Chrome and updated the manifest to include "background": { "service_worker": "bg.js", "type": "module" } However, Chrome is now giving me "Service worker registration failed". Any thoughts as to why? Also I am using Firebase so I can communicate between the Chrome Extension for different users and other Web Servers, would this not work? – Mike Harb Sep 28 '21 at 21:36
  • I guess you can't use `import` inside `try`. Click the `Errors` button to see the details. – wOxxOm Sep 28 '21 at 21:43
  • Thank you very much, it worked and I received the initializeApp(firebaseConfig) object! – Mike Harb Sep 28 '21 at 22:19

0 Answers0