使用typescript设置Firebase服务帐户时出错

时间:2018-06-07 11:18:15

标签: node.js firebase firebase-admin

根据Firebase控制台,为了设置服务帐户,我需要包含以下代码段:

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

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

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

我已将json放在与index.ts相同的文件夹中:

// src/index.ts
import * as admin from 'firebase-admin'
var serviceAccount = require('./firebaseServiceAccountKey.json');

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

然而,当我上传firebase函数时,我收到此错误:

Error: Error occurred while parsing your function triggers.

SyntaxError: /home/woowapdabug/projects/    Error: Error occurred while parsing your function triggers.

SyntaxError: /home/woowapdabug/projects/server/functions/lib/firebaseServiceAccountKey.json: Unexpected token / in JSON at position 2364
    at JSON.parse (<anonymous>)
    at Object.Module._extensions..json (module.js:671:27)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/woowapdabug/projects/server/functions/lib/index.js:5:22)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)server/functions/lib/firebaseServiceAccountKey.json: Unexpected token / in JSON at position 2364
    at JSON.parse (<anonymous>)
    at Object.Module._extensions..json (module.js:671:27)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/home/woowapdabug/projects/server/functions/lib/index.js:5:22)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)

0 个答案:

没有答案