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.

[vite dev] Error loading external error with firebase

See original GitHub issue

Discussed in https://github.com/nuxt/framework/discussions/3525

<div type='discussions-op-text'>

Originally posted by akhilnarayanan1 March 6, 2022

Environment

  • Operating System: Windows_NT
  • Node Version: v16.13.1
  • Nuxt Version: 3.0.0-27451165.114cbe3
  • Package Manager: npm@7.21.1
  • Bundler: Vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -
  • Firebase: 9.6.8

Reproduction

  1. npx nuxi init nuxt3-app cd nuxt3-app npm install npm install firebase

  2. Create plugins/firebase.client.ts (replace firebaseConfig parameters)

import { defineNuxtPlugin } from "#app";

import { FirebaseApp, initializeApp } from "firebase/app";
import { Firestore, getFirestore } from "firebase/firestore";
import { initializeAuth, browserLocalPersistence, browserSessionPersistence, 
  indexedDBLocalPersistence, Auth} from "firebase/auth";

declare module "#app" {
  interface NuxtApp {
    $firebaseApp: FirebaseApp;
    $firebaseAuth: Auth;
    $firebaseDB: Firestore;
  }
};

export default defineNuxtPlugin((nuxtApp) => {
 
  const firebaseConfig = {
    apiKey: "XXXX",
    authDomain: "XXX",
    projectId: "XXX",
    storageBucket: "XXX",
    messagingSenderId: "XXX",
    appId: "XXX",
    measurementId: "XXX",
  }; // 🔁 change this

  const app = initializeApp(firebaseConfig);
  const auth = initializeAuth(app, {
    persistence: [indexedDBLocalPersistence, browserSessionPersistence, browserLocalPersistence],
  });
  const db = getFirestore(app);

  nuxtApp.provide("firebaseApp", app);
  nuxtApp.provide("firebaseAuth", auth);
  nuxtApp.provide("firebaseDB", db);
});

  1. Edit app.vue
<template>
  <div>
    <NuxtWelcome />
  </div>
</template>

<script setup lang="ts">
  import { doc } from "firebase/firestore";

  const { $firebaseDB } = useNuxtApp();

  onMounted(()=>{
    const docRef = doc($firebaseDB, "users", 'something'); // 🔥 ERROR with this line 
  })

</script>

Describe the bug

When I add const docRef = doc($firebaseDB, "users", 'something'); , I get an error -> [vite dev] Error loading external in browser when using firebase firestore and below error in VSCode terminal

ReferenceError: IDBIndex is not defined
    at file:///C:/project/personal/work/nuxt-issue/nuxt3-app/node_modules/idb/lib/idb.mjs:87:38
    at ModuleJob.run (node:internal/modules/esm/module_job:185:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:281:24)
    at async __instantiateModule__ (file:///C:/project/personal/work/nuxt-issue/nuxt3-app/.nuxt/dist/server/server.mjs:25837:3)

Additional context

There is no such issue when I try to add ssr: false in nuxt.config.ts

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
akhilnarayanan1commented, Mar 23, 2022

Looks like this issue was from firebase, when I upgraded v9.6.8 to v9.6.9, everything is working again

1reaction
hecateballcommented, Mar 15, 2022

I got the same error.

It seems to be the problem that nuxt dev uses firebase/firestore/dist/index.esm.js (which is declared as exports.default in firebase package.json ) even for server assets.

Workaround: set alias for firebase/app and firebase/firestore in nuxt.config.js to explicitly use .mjs build.

export default defineNuxtConfig({
  alias: {
    'firebase/app': 'firebase/app/dist/index.mjs',
    'firebase/firestore': 'firebase/firestore/dist/index.mjs',
  },
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Exports is not defined while using firestore - firebase
I am using it with svelte kit. I am following the docs on the firebase website and I think this error comes in...
Read more >
Firebase JavaScript SDK Release Notes - Google
Prevent the SDK from throwing errors if it is unable to log platform data due to an IndexedDB error. It will log a...
Read more >
A Vue Firebase Authentication Tutorial - Vue 3 and Firebase
cd vue-firebase-authenticationnpm installnpm run dev. Our Vite app is now up and running. We can navigate to http://localhost:3000 and see ...
Read more >
Must-Know Reusable Module Vs Component In Vue 3 ...
As a Vue.js developer, we want to keep our code clean and tidy by creating the optimal amount of reusable code. With Composition...
Read more >
Server-Side Rendering - Vite
Throw an error if any Node.js built-ins are imported. Vite CLI #. The CLI commands $ vite dev and $ vite preview can...
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