Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.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
Node.js 请求外部网络资源!-来自firebase emulator的日志错误_Node.js_Firebase_Express_Google Cloud Firestore_Google Cloud Functions - Fatal编程技术网

Node.js 请求外部网络资源!-来自firebase emulator的日志错误

Node.js 请求外部网络资源!-来自firebase emulator的日志错误,node.js,firebase,express,google-cloud-firestore,google-cloud-functions,Node.js,Firebase,Express,Google Cloud Firestore,Google Cloud Functions,我尝试注册并登录firebase。我使用Firebase(消防商店), 快递邮递员(RESTAPI) 我的代码(index.js) firebase.json文件 { "emulators": { "functions": { "port": 5001 }, "ui": { "enabled": true }, "hosting": { "port": 5000 } }, "hosting": {

我尝试注册并登录firebase。我使用Firebase(消防商店), 快递邮递员(RESTAPI)

我的代码(index.js)

firebase.json文件

{
  "emulators": {
    "functions": {
      "port": 5001
    },
    "ui": {
      "enabled": true
    },
    "hosting": {
      "port": 5000
    }
  },
  "hosting": {
    "public": "public",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

我正在使用firebase模拟器启动firebase模拟器:start 我在启动firebase emulator时没有收到任何错误,但是它工作正常,有一个警告,如

!  functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
如果我使用post发送任何get或post请求,我将从仿真器获取错误日志

!  External network resource requested!
   - URL: "http://169.254.169.254/computeMetadata/v1/instance"
 - Be careful, this may be a production service.
!  External network resource requested!
   - URL: "http://metadata.google.internal./computeMetadata/v1/instance"
 - Be careful, this may be a production service.
>  Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.

我不知道如何摆脱它。如果您能在这件事上给我任何帮助,我将不胜感激。

我也遇到了同样的问题,问题似乎归结为
admin.initializeApp()需要不同于您可能提供的信息

我发现这里有帮助

我猜您是从控制台>项目设置>常规>应用程序>Firebase SDK代码片段中获得了配置JSON。这就是我正在使用的,并且不断地出现这个错误

然后,我按照答案的建议做了。转到控制台>项目设置>服务帐户。在那里你会发现一个蓝色的按钮,上面写着“生成新的私钥”。下载该密钥,并将其保存到您的项目中(如果愿意,请重命名)。然后,如该页所示,使用以下代码进行初始化

var admin = require("firebase-admin");

var serviceAccount = require("path/to/serviceAccountKey.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://projectname.firebaseio.com"
});

可能值得注意的是,
databaseURL
位可以在当前的
config

中找到。首先,常规firebase帐户有一些限制

一旦进入blaze计划等,请确保“项目设置”>服务帐户选项卡>Firebase管理SDK

生成新的服务密钥

然后使用下面的代码映射正确的服务帐户json

var admin = require("firebase-admin");

 var serviceAccount = require("Mention path to service Account key.json")

 admin.initializeApp({
   credential: admin.credential.cert(serviceAccount)
})
谢谢你

var admin = require("firebase-admin");

 var serviceAccount = require("Mention path to service Account key.json")

 admin.initializeApp({
   credential: admin.credential.cert(serviceAccount)
})