[vite dev] Error loading external error with firebase
See original GitHub issueDiscussed 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
-
npx nuxi init nuxt3-app
cd nuxt3-app
npm install
npm install firebase
-
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);
});
- 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:
- Created 2 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like this issue was from firebase, when I upgraded v9.6.8 to v9.6.9, everything is working again
I got the same error.
It seems to be the problem that
nuxt dev
usesfirebase/firestore/dist/index.esm.js
(which is declared as exports.default infirebase
package.json ) even for server assets.Workaround: set
alias
for firebase/app and firebase/firestore in nuxt.config.js to explicitly use .mjs build.