firebase-module: Nuxt Generate + RealtimeDatabase / Firestore results in "Nuxt Generate finished but did not exit"
When using nuxt generate, the following warning appears at the end (after a successful generate)
Problem
⚠ 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
$fireDbor$fireStorein 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)
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 26 (11 by maintainers)
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:What I am doing is:
builder.options.firebase.config./.nuxt/firebase/app.jsgoOffline()/terminate()on RealtimeDatabase and Firestore through that instanceI 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
generate:donehookSo a short-term solution I’ve determined from these two posts is:
{project_root}/firebase.config.js:plugins/firebaseInit.jsfile:nuxt.config.jsto import the config file and add a generate.done() hook around the plugin:Added option to automatically terminate databases with v7.5.0, hope that works for everyone!
See documentation: https://firebase.nuxtjs.org/guide/options#terminateDatabasesAfterGenerate
Some further development: Adding the firebase session to the generator object like so:
from that moment on firebase is accessible in all generate hooks.
I think this would be a nice addition to the module. adding the firebase instance to the generate property and making it accessible
As I am currently extending routes and providing payloads through the generate hooks, I am using it in multiple hooks. Without the need of seperate imports etc.
Thank you for showing me how to work with hooks!
@mandalornl Not a big fan of adding code “just to be safe”… The import of Firestore & Database should not be needed since we already import them when instantiating them.
Thanks for letting me know about the SIGSEGV error, interesting. It’s working just fine for me. Can you share some details about your environment? Does that error only appear within docker? Which node.js version are you using? Have you tried using a more current version?
It does work for me as well when using require(), so I might change the code to that, but first would like to know what the issue could be.
Thanks for your support!
@mandalornl thanks for posting! Yours is the only one that worked out-of-the-box for me
Yes i posted it as a feature request.
nuxt generatedoesn’t create the.nuxtfolder. Therefore for production i run “nuxt build && nuxt generate”nuxt buildcreates the.nuxtfolder andnuxt generateis smart enough not to re-build again, so no time is lost. https://github.com/nuxt/nuxt.js/issues/8365I had to import
firebase/appinstead of./.nuxt/firebase/app, because the latter could not be found by ourdockerbuild server. The followingnuxt.config.jsexample seems to work though.Fantastic! Works like a charm, this cost me 2 days of hunting and trying. definitely need to learn some more of the indepth nuxt workings. Didnt really know what to do with hooks. (☞゚ヮ゚)☞
Reopened because issue still exists, also see (https://github.com/nuxt-community/firebase-module/issues/373).
Will try to find a solution that does not require a workaround.
I’d like to add that this is still relevant on the new target: static Nuxt functions; nuxt build & nuxt export