Nuxt生成并且Firebase发出计时器警告

问题描述 投票:0回答:1

我正在基于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        │
   │                                                                                      │
   ╰──────────────────────────────────────────────────────────────────────────────────────╯

根据this post的建议,我添加了以下代码段:

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.   │
   │                                                                                        │
   ╰────────────────────────────────────────────────────────────────────────────────────────╯

这是我的路线方法,部分取自this question

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

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

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

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 :{...}
}

我正在基于Firestore中的集合在Nuxt.js中动态生成路由。一切都很好,但随后发出此警告。 ╭──────────────────────────────── ────────...

firebase google-cloud-firestore nuxt.js dynamic-links
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.