0

我正在根据 firestore 中的集合在 Nuxt.js 中动态生成路由。一切都很好,但随后它给出了这个警告。

   ╭──────────────────────────────────────────────────────────────────────────────────────╮
   │                                                                                      │
   │   ⚠ 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        │
   │                                                                                      │
   ╰──────────────────────────────────────────────────────────────────────────────────────╯

根据这篇文章的建议,我添加了以下代码段:

export default {
  hooks: {
    generate: {
      done(builder) {
        firebase.firestore.terminate()
      }
    }
  },
}

但这会产生一个致命错误:

 FATAL  The client has already been terminated.                                                                                       23:39:58  

  at new FirestoreError (node_modules\@firebase\firestore\dist\index.node.cjs.js:1201:28)
  at FirestoreClient.verifyNotTerminated (node_modules\@firebase\firestore\dist\index.node.cjs.js:17311:19)
  at FirestoreClient.listen (node_modules\@firebase\firestore\dist\index.node.cjs.js:17371:14)
  at CollectionReference.Query$1.onSnapshotInternal (node_modules\@firebase\firestore\dist\index.node.cjs.js:21820:48)
  at CollectionReference.Query$1.getViaSnapshotListener (node_modules\@firebase\firestore\dist\index.node.cjs.js:21851:29)
  at node_modules\@firebase\firestore\dist\index.node.cjs.js:21846:23
  at new Promise (<anonymous>)
  at CollectionReference.Query$1.get (node_modules\@firebase\firestore\dist\index.node.cjs.js:21836:16)
  at routes (nuxt.config.js:185:79)
  at promisifyRoute (node_modules\@nuxtjs\sitemap\lib\cache.js:59:17)
  at AsyncCache.load [as _load] (node_modules\@nuxtjs\sitemap\lib\cache.js:18:28)
  at AsyncCache.get (node_modules\async-cache\ac.js:63:8)
  at internal/util.js:297:30
  at new Promise (<anonymous>)
  at AsyncCache.get (internal/util.js:296:12)
  at generateSitemap (node_modules\@nuxtjs\sitemap\lib\generator.js:54:37)


   ╭────────────────────────────────────────────────────────────────────────────────────────╮
   │                                                                                        │
   │   ✖ Nuxt Fatal Error                                                                   │
   │                                                                                        │
   │   FirebaseError: [code=failed-precondition]: The client has already been terminated.   │
   │                                                                                        │
   ╰────────────────────────────────────────────────────────────────────────────────────────╯

这是我的路线方法,部分来自这个问题

generate: {
    async routes() {
      const collection = await db.collection('restaurants').get();
      return collection .docs.map(x => `/restaurant/${x.title}`);
    }
},

仅当我添加生成对象时才出现此警告,因此我知道问题出在该区域。有什么建议么?

编辑:Firebase 初始化代码nuxt.config.js

import firebase from 'firebase/app'
import 'firebase/firestore'

const config = {
  apiKey: '',
  authDomain: '',
  databaseURL: '',
  projectId: '',
  storageBucket: '',
  messagingSenderId: '',
  appId: '',
  measurementId: ''
};
firebase.initializeApp(config);
const fireDb = firebase.firestore();

export default {
    generate :{...}
}
4

4 回答 4

1

如果您仍需要帮助,可以直接与 Firebase 联系,因为他们在此处提供免费支持:https ://firebase.google.com/support/troubleshooter/contact

于 2020-05-25T19:06:40.433 回答
0

对于那些仍然无法解决这个问题的人,nuxt firebase 模块有一个配置标志来终止生成:

终止数据库后生成:真

在此处查看文档:https ://firebase.nuxtjs.org/guide/options/

于 2021-02-21T20:11:13.680 回答
0

plugins/firebase.js您应该导出fireDb,您可以导入任何组件并使用该变量,如下所示

plugins/firebase.js

import firebase from 'firebase/app';
import 'firebase/database';

if (!firebase.apps.length) {
  const config = {
    apiKey: '',
    authDomain: '',
    databaseURL: '',
    projectId: '',
    storageBucket: '',
    messagingSenderId: ''
  };
  firebase.initializeApp(config);
}

const fireDb = firebase.firestore();

export { fireDb };
于 2020-05-02T09:09:06.403 回答
0

新的:

这是节点和实时数据库的问题。

以下工作无需终止进程: this.$fire.database.goOffline()


旧有副作用(请勿使用):

有关解决方案,请参阅以下 stackoverflow。我可以确认这process.exit()适用于我的用例。

节点进程在firebase一次后不会退出

于 2020-11-06T14:36:14.663 回答