firebase-tools getaddrinfo ENOTFOUND metadata.google.internal

时间:2018-10-09 14:30:11

标签: javascript node.js firebase firebase-admin

我的终端出现此错误:

@firebase/database: FIREBASE WARNING: {"code":"app/invalid- 
credential","message":"Credential implementation provided to . 
initializeApp() via the \"credential\" property failed to fetch a valid 
Google OAuth2 access token with the following error: \"Failed to parse 
access token response: Error: Error while making request: getaddrinfo 
ENOTFOUND metadata.google.internal metadata.google.internal:80. Error 
code: ENOTFOUND\"."}`

使用firebase-tools时。这是我要运行的简单节点脚本。

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

const firebase = admin.initializeApp({
  apiKey: "MY_API_KEY",
  authDomain: "APP_ID.firebaseapp.com",
  databaseURL: `https://DATABASE_URL.firebaseio.com`,
  projectId: "APP_ID"
});

const snap = firebase
  .database()
  .ref("REF")
  .child("ID")
  .once("value");
console.log(snap);

Firebase工具版本:5.0.1

我尝试使用firebase login / firebase-logout卸载和重新安装,登录和注销firebase-tools

2 个答案:

答案 0 :(得分:2)

配置结构错误,缺少字段...

admin.initializeApp({
    databaseURL: 'https://<DATABASE_NAME>.firebaseio.com',
    credential: admin.credential.cert({
        projectId: '<PROJECT_ID>',
        clientEmail: 'foo@<PROJECT_ID>.iam.gserviceaccount.com',
        privateKey: '-----BEGIN PRIVATE KEY-----\n<KEY>\n-----END PRIVATE KEY-----\n'
    })
});

您不能仅使用“网络”配置来访问Firebase Admin SDK。

因为这是可能的,所以私钥将公开给公众。

请参见documentation

答案 1 :(得分:0)

我只需运行即可解决它:

firebase login

当我没有互联网连接时,我也会遇到此错误。