1

The following code works as expected. However, I do get a warning:

⚠ Nuxt Warning The command 'nuxt generate' finished but did not exit after 5s ... ... DeprecationWarning: Starting with Nuxt version 3 this will be a fatal error

This is not nice. Getting the error in Netlify and also when testing on the localhost. Here is my nuxt.config:

generate: {
    routes() {
      // generate portfolio pages
      const firebase = require("firebase");
      let app;
      if (!firebase.apps.length) {
        app = firebase.initializeApp(require("./config/firebase"));
      } else {
        app = firebase.apps[0];
      }
      const firestore = firebase.firestore();
      const mapDocToRoute = doc => {
        const data = doc.data();
        console.log(data);
        return {
          route: `/portfoolio/${data.slug}`
          // payload: { ...data }
        };
      };

      return new Promise(async (resolve, reject) => {
        try {
          const portfolioQuery = await firestore.collection("portfolio").get();

          const docRoutes = [];
          portfolioQuery.forEach(doc => {
            docRoutes.push(mapDocToRoute(doc));
          });

          await app.delete();
          app = null;

          resolve(docRoutes);
        } catch (e) {
          // reject(e);
          resolve([]);
        }
      });
    }
  }

Help is appreciated.

paul-shuvo
  • 1,874
  • 4
  • 33
  • 37
indrek0
  • 13
  • 4
  • I should probably using the Firebase REST API for this kind of situation. However it would still be good to know what's preventing Nuxt generate to exit properly. – indrek0 Feb 08 '20 at 09:12
  • Did you find a solution to this? – SRR Aug 07 '20 at 20:26
  • 1
    Figured I shouldnt be logging in directly to "firebase" during the generate process. The better way is to create a simple REST endpoint (could be serverless) to access Firebase data and then make a simple http request during Netlify generate – indrek0 Aug 10 '20 at 12:39

1 Answers1

1

For version 9 of the Firebase SDK and assuming you've set up the plugin as detailed in this article:

nuxt.config.js


import {db} from './plugins/firebase';
import { terminate } from "firebase/firestore";
export default{
  ...
  hooks: {
    generate: {
      async done(builder) {
        try {
          await terminate(db);
        } catch (e) { console.error(e) }
      },
    },
  }, 
}
SRR
  • 1,608
  • 1
  • 21
  • 51