Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nuxt生成和firebase发出计时器警告_Firebase_Google Cloud Firestore_Nuxt.js_Dynamic Links - Fatal编程技术网

Nuxt生成和firebase发出计时器警告

Nuxt生成和firebase发出计时器警告,firebase,google-cloud-firestore,nuxt.js,dynamic-links,Firebase,Google Cloud Firestore,Nuxt.js,Dynamic Links,我正在基于firestore中的集合在Nuxt.js中动态生成路由。一切都很好,但它会发出警告 ╭──────────────────────────────────────────────────────────────────────────────────────╮ │ │ │ ⚠ Nuxt Warn

我正在基于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对象时才会出现,所以我知道问题出在那个区域。有什么建议吗

编辑:
numxt.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 :{...}
}
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 };

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

plugins/firebase.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 :{...}
}
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 };

如果您仍然需要帮助,您可以直接联系Firebase,因为他们在此处提供免费支持:

新建:

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

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


有副作用的老年人(不要使用):

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


对于那些仍然无法修复此问题的用户,nuxt firebase模块具有一个配置标志,用于在生成时终止此操作:

TerminatedDatabaseSafterGenerate:true


在此处查看文档:

您能分享您的firebase初始化代码吗?@HardikShah donefirebase初始化代码位于
numxt.config.js
或作为
插件
!!!请尝试作为一个插件。在该代码中使用firestore进行的任何初始化,比如连接到特定的商店???@HardikShah,我在插件中有它。但是如果我在
nuxt.config.js
中从'@/plugins/firebase'
导入{fireDb},我会得到
找不到模块'@/plugins/firebase'
,所以我现在就求助于另一种方法,你是从
plugins/firebase.js
导出
firebase.database()还是从
plugins/firebase.firebase.js()导出
我的坏!在我的情况下,它是你们的数据库,它是FireStore,这是我已经拥有的。我在项目中的
.vue
文件中使用
fireDb
,以便正确导出它。我就是无法在
numxt.config.js中访问它
我不知道你为什么需要在numxt.config.js中使用它,你能解释一下吗!??这样我就可以生成动态路由。所以在我的数据库中有一个叫做餐馆的集合,我希望每个餐馆都有自己的路线(第页)。但我不想手动创建它们,所以我使用nuxt根据该集合生成路由。很抱歉,更新导致数据库无法注入。当我修复了这个问题,并且数据库正在工作时,超时又开始了。一旦向数据库发出请求,超时将再次开始。。。有趣的是,它说的是V.6,但它让我按照V.7的要求进行迁移。。。因此,尽管有json软件包,我想我还是在
nuxtjs/firebase^7
啊,在这种情况下,我没有使用
@nuxtjs/firebase
为没有在问题中明确说明这一点表示歉意。好吧,这并不重要,因为最后
nuxtjs/firebase
只是一个预先制作的插件。没有区别,也许我误解了
@nuxtjs/firebase
是一个控制
firebase
的插件。因为我没有在项目中使用插件,所以我没有看到一个引用插件升级的答案如何成为我用例的解决方案。我用一个有效的解决方案更新了我的答案!