Directory import ‘[~]/node_modules/firebase/app’ is not supported resolving ES modules imported from /[~]
Did you mean to import firebase/app/dist/index.cjs.js?

Fredric Cliver
2 min readAug 11, 2020

--

When you applying Firebase into your Node.js project, You faces a bunch of errors.

Here is the most common errors.

.. is not supported resolving ES modules imported from ..

// Firebase App (the core Firebase SDK) is always required and
// must be listed before other Firebase SDKs
import * as firebase from "firebase/app";

// Add the Firebase services that you want to use
import "firebase/auth";
import "firebase/firestore";

https://firebase.google.com/docs/web/setup?authuser=0#node.js-apps

This is the official guide. But it doesn’t work.

** Enviroments **➜ node --version
v14.7.0
➜ npm --version
6.14.7
** package.json **"dependencies": {
"firebase": "^7.17.2"
}

So you have to add a scoped package symbol ‘@’

import * as firebase from "@firebase/app"
import "@firebase/auth"
import "@firebase/firestore"

Now, the error is changed.

It has not the function, the initializeApp function.

import firebase from "@firebase/app"// import * as firebase from "@firebase/app"

if you import firebase as partly, not just whole package. you have to set the firebase/app package as just firebase.

//importing whole package
import firebase from "firebase"

and You have to change the way to call the initializing function.

// it doesn't work.
// firebase.initializeApp(firebaseConfig)
// step into more with default.
firebase.default.initializeApp(firebaseConfig)

You will succeed to run.

Full Code

import firebase from "@firebase/app"
import "@firebase/auth"
import "@firebase/firestore"
...firebase.default.initializeApp(firebaseConfig)
This is not working with Node v14.+

--

--

Fredric Cliver
Fredric Cliver

Written by Fredric Cliver

Physics graduate with 13 years of diverse experience in the IT industry. Founded and managed a startup for 3 years.