Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.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
为什么firebase cli会给出类型错误_Firebase_Google Cloud Functions_Firebase Cli_Sendgrid Api V3 - Fatal编程技术网

为什么firebase cli会给出类型错误

为什么firebase cli会给出类型错误,firebase,google-cloud-functions,firebase-cli,sendgrid-api-v3,Firebase,Google Cloud Functions,Firebase Cli,Sendgrid Api V3,我已经有一些运行良好的firebase云函数,现在我尝试将SendGrid功能添加到其中一个函数中,如中所述。firebase CLI不会运行我的代码,因为它说它有一个TypeError 代码是用Typescript编写的,transpiler不会给出任何错误。我正在使用最新版本的CLI和SDK admin.initializeApp(); const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG); const SENDGRI

我已经有一些运行良好的firebase云函数,现在我尝试将SendGrid功能添加到其中一个函数中,如中所述。firebase CLI不会运行我的代码,因为它说它有一个TypeError

代码是用Typescript编写的,transpiler不会给出任何错误。我正在使用最新版本的CLI和SDK

admin.initializeApp();

const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
const SENDGRID_API_KEY = firebaseConfig.sendgrid.key;

const sgMail = require(‘@sendgrid/mail’);
sgMail.setApiKey(SENDGRID_API_KEY);
我已检查firebase配置是否包含sendgrid密钥:

$ firebase functions:config:get
{
    "sendgrid": {
      "key": "MY_SEND_GRID_KEY"
    }
} 
我在尝试部署时得到此输出--仅限函数:

函数:未能加载函数源代码。通过在functions目录中运行npm i--save firebase函数,确保您拥有最新的SDK:警告:函数:来自模拟器的错误。分析函数触发器时出错

TypeError:无法读取未定义的属性“key”

这一行有错误:

const SENDGRID_API_KEY = firebaseConfig.sendgrid.key;

我可以更改什么以避免出现此错误?

使用CLI通过
firebase函数:config:get
设置的变量不会以
process.env.firebase\u config
结束。它们最终位于
functions.config()

FIREBASE_CONFIG只确定如何初始化admin SDK,而不向admin.initializeApp()传递任何参数


使用CLI通过
firebase函数:config:get设置的变量不会在
process.env.firebase\u config
中结束。它们最终位于
functions.config()

FIREBASE_CONFIG只确定如何初始化admin SDK,而不向admin.initializeApp()传递任何参数


我尝试了这一点,在部署功能时,它会起作用。但是,当我从模拟器运行时,仍然会得到“TypeError:cannotreadproperty'key'ofundefined”。仿真器没有从服务器读取配置吗?如果没有,是否有办法在本地设置它,以便可以使用仿真器?请阅读本地仿真器上的文档。您必须将配置转储到本地文件,以便emulator读取。我尝试了这个,当我部署我的函数时它就起作用了。但是,当我从模拟器运行时,仍然会得到“TypeError:cannotreadproperty'key'ofundefined”。仿真器没有从服务器读取配置吗?如果没有,是否有办法在本地设置它,以便可以使用仿真器?请阅读本地仿真器上的文档。您必须将配置转储到本地文件,以便emulator读取。
import * as functions from 'firebase-functions'
const key = functions.config().sendgrid.key