question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ES6 module cannot import firebase

See original GitHub issue

[REQUIRED] Describe your environment

  • Operating System version: MacOS 10.13.6
  • Browser version: Chrome 83.0.4103.61
  • Firebase UI version: 3.5.2
  • Firebase SDK version: 7.14.0

[REQUIRED] Describe the problem

Steps to reproduce:

I am using import * as firebaseui from 'firebaseui' to import firebaseui as an ES module (built with rollup) from node_modules/firebaseui/dist/esm.js. This module tries to import firebase using import * as firebase from 'firebase/app' from node_modules/firebase/app/dist/index.esm.js, however this does not work an errors with auth is not exported by node_modules/firebase/app/dist/index.esm.js. Instead it should be importing firebase with import firebase from 'firebase/app' which works as expected.

Relevant Code:

https://stackblitz.com/fork/firebase-issue-sandbox

import firebase from "firebase/app";
import "firebase/auth";

var firebaseConfig = {
 // ...
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
import * as firebaseui from "firebaseui";

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
brandonaaroncommented, Sep 17, 2020

I also experienced this issue and used “string-replace-loader” to replace the import * as firebase from 'firebase/app' to import firebase from 'firebase/app'. This was inspired by an older issue in this project that I stumbled on.

  {
    test: /esm\.js$/,
    loader: 'string-replace-loader',
    include: path.resolve('node_modules/firebaseui/dist'),
    query: {
      search: "import * as firebase from 'firebase/app';",
      replace: "import firebase from 'firebase/app';",
    }
  }

I’m using the latest preact-cli and I’m not sure this is a universal fix for other setups but this worked for me. Open source project for reference.

@bojeil-google this still seems like an active issue related to esm builds.

1reaction
IanBellomycommented, Jul 29, 2020

Running into the same issue I think. Using rollup resolve with a firebaseui import and get the same message as reported.

Per @maxwell8888’s note, @bojeil-google’s suggestion to use import * as firebase... causes other issues.

Also tried @maxwell8888 's solution but ended up with a new issue…

[!] Error: 'default' is not exported by node_modules/dialog-polyfill/dialog-polyfill.js, imported by node_modules/firebaseui/dist/esm.js

and had to make the following change:

// import dialogPolyfill from 'dialog-polyfill';
import * as dialogPolyfill from 'dialog-polyfill';
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I import firebase-database as an es6 module
2 Answers 2 ; import * as ; "firebase/app"; // If you enabled Analytics in your project, add the Firebase SDK for Analytics...
Read more >
Alternative ways to add Firebase to your JavaScript project
You can configure partial import of the Firebase JavaScript SDK and only load the Firebase products that you need. Firebase stores each library ......
Read more >
Directory import '[~]/node_modules/firebase/app' is not ...
When you applying Firebase into your Node.js project, You faces a bunch of errors. Here is the most common errors. .. is not...
Read more >
How to deploy a firebase function packaged as ES6 module
import * as functions from "firebase-functions"; import myGreeting from ". ... Cannot find module '/functions/lib/my-greeting' imported from ...
Read more >
Cannot use import statement outside module in JavaScript
The SyntaxError: Cannot use import statement outside a module occurs when we use the ES6 Modules syntax in a script that was not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found