【发布时间】:2020-08-15 14:12:32
【问题描述】:
我在 Nuxt.js 中基于 firestore 中的集合动态生成路由。一切正常,但随后会发出此警告。
╭──────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ ⚠ 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 的建议,我添加了以下 sn-p:
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}`);
}
},
此警告仅在我添加生成对象时出现,因此我知道问题出在该区域。有什么建议?
编辑: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 :{...}
}
【问题讨论】:
-
你能分享你的firebase初始化代码吗?
-
@HardikShah 完成
-
firebase 初始化代码在
nuxt.config.js或plugin!!!请尝试作为插件。在该代码中使用 firestore 进行任何初始化,例如连接到特定商店?? -
@HardikShah 我在插件中有它。但是如果我在
nuxt.config.js中执行import {fireDb} from '@/plugins/firebase'我得到Cannot find module '@/plugins/firebase'所以我现在采用了另一种方法 -
你是从
plugins/firebase.js导出fireDb吗?
标签: firebase google-cloud-firestore nuxt.js dynamic-links