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.

Nuxt Generate + RealtimeDatabase / Firestore results in "Nuxt Generate finished but did not exit"

See original GitHub issue

When using nuxt generate, the following warning appears at the end (after a successful generate)

Problem

Screenshot 2020-11-08 at 15 19 20
⚠ Nuxt Warning 

The command 'nuxt generate' finished but did not exit after 5s
This is most likely not caused by a bug in Nuxt.js
Make sure to cleanup all timers and listeners you or your plugins/modules start.
Nuxt.js will now force exit

DeprecationWarning: Starting with Nuxt version 3 this will be a fatal error  

Possible Solution

It can theoretically be fixed by calling goOffline() for RealtimeDb or terminate() for Firestore after the generate:done hook.

export default {
  hooks: {
    generate: {
      done(builder) {
        $fireDb.goOffline()
        $fireStore.goOffline()
      }
    }
  },
  • Problem now is: How do we access $fireDb or $fireStore in this hook and how do we implement this in nuxt-firebase?

Might be a big issue when Nuxt v3 arrives.

(Originated from https://github.com/lupas/nuxt-fire/issues/90#issuecomment-590052067)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:26 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
lupascommented, Nov 9, 2020

Alright guys, so I found a way to make this work without having to create any additional files. Just do the following in your nuxt.config.js:

hooks: {
  generate: {
    async done(builder) {
      const appModule = await import('./.nuxt/firebase/app.js')
      const { session } = await appModule.default(
        builder.options.firebase.config,
        {
          res: null,
        }
      )
      try {
        session.database().goOffline()
      } catch (e) { }
      try {
        session.firestore().terminate()
      } catch (e) { }
    },
  },
},

What I am doing is:

  1. Take the Firebase config out of builder.options.firebase.config
  2. Get the Firebase instance from ./.nuxt/firebase/app.js
  3. Call goOffline() / terminate() on RealtimeDatabase and Firestore through that instance

I assume that with Nuxt 3 the API and possibly the hooks will change quite a bit so that this has to be reevaluated anyway (maybe we can access the context in the hooks then?). Until Nuxt 3 is released (possibly around Q1 2021) this should be a good workaround.

ToDo’s

3reactions
EvanLomascommented, Nov 8, 2020

So a short-term solution I’ve determined from these two posts is:

  1. Move your firebase config to a shared file such as {project_root}/firebase.config.js:
module.exports = {
  apiKey: "...",
  authDomain: "...",
  databaseURL: "...",
  projectId: "...",
  storageBucket: "...",
  messagingSenderId: "...",
  appId: "...",
  measurementId: "..."
}
  1. Create a plugins/firebaseInit.js file:
import firebase from 'firebase/app'
import 'firebase/database'
import 'firebase/firestore'

if (!firebase.apps.length) {
  firebase.initializeApp(require('../firebase.config.js'))
}

export const fireDb = firebase.database()
export const fireStore = firebase.firestore()
  1. Change your nuxt.config.js to import the config file and add a generate.done() hook around the plugin:
import { fireDb, fireStore } from './plugins/firebaseInit.js'

export default {
  // ...
  modules: [
    // ...
    [
      '@nuxtjs/firebase',
      {
        config: require('./firebase.config.js'),
        services: {
          auth: true,
          realtimeDb: true,
          firestore: true,
          // ...
        }
      }
    ]
  ],
  // ...
  hooks: {
    generate: {
      done(builder) {
        try { fireDb.goOffline() } catch (e) { }
        try { fireStore.terminate() } catch (e) { }
      }
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt Generate finished but did not exit #90 - GitHub
I am not using Vuex, but I am using the onSnapshot method, which is what I have narrowed the issue down to. It...
Read more >
Nuxt generate and firebase gives timer warning - Stack Overflow
So that I can generate dynamic routes. So there's a collection in my database called restaurants and I want each restaurant to have...
Read more >
Options - Nuxt Firebase
Your firebase config snippet and other Firebase specific parameters. ... The command 'nuxt generate' finished but did not exit after 5s This is...
Read more >
Firebase - Nuxt.js Succinctly Ebook - Syncfusion
Learn about overview, getting started with firebase and adding data in the chapter "Firebase" of Syncfusion Nuxt.js free ebook.
Read more >
Building User Accounts with Nuxt, Vuex, and Firebase
Recently, I was working to implement user accounts into my application I've been building with Nuxt as the frontend and Firebase for the ......
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