&引用;确定执行环境时出现意外错误“;运行Firebase emulator时
当我部署我的函数时,一切都正常工作,但使用Firebase emulator在本地运行相同的代码会导致以下错误:&引用;确定执行环境时出现意外错误“;运行Firebase emulator时,firebase,google-cloud-functions,Firebase,Google Cloud Functions,当我部署我的函数时,一切都正常工作,但使用Firebase emulator在本地运行相同的代码会导致以下错误: { "message": "Unexpected error determining execution environment: request to http://169.254.169.254/computeMetadata/v1/instance failed, reason: connect EHOSTDOWN 169.254.169.254:80 - Local (1
{
"message": "Unexpected error determining execution environment: request to http://169.254.169.254/computeMetadata/v1/instance failed, reason: connect EHOSTDOWN 169.254.169.254:80 - Local (192.168.1.101:56456)",
"type": "system",
"errno": "EHOSTDOWN",
"code": "EHOSTDOWN",
"config": {
"url": "http://169.254.169.254/computeMetadata/v1/instance",
"headers": {
"Metadata-Flavor": "Google"
},
"retryConfig": {
"noResponseRetries": 0,
"currentRetryAttempt": 0,
"retry": 3,
"retryDelay": 100,
"httpMethodsToRetry": [
"GET",
"HEAD",
"PUT",
"OPTIONS",
"DELETE"
],
"statusCodesToRetry": [
[
100,
199
],
[
429,
429
],
[
500,
599
]
]
},
"responseType": "text",
"timeout": 3000,
"params": {},
"method": "GET"
}
}
我应该怎么做才能用emulator测试我的代码?如果您的云功能需要管理员权限,那么您需要为云功能配置一个服务帐户来运行 请按照此处的说明操作: 主要步骤如下: 1) 创建服务帐户并下载.json私钥文件(保密) 在运行模拟器的控制台中: 2) 将GOOGLE_APPLICATION_CREDENTIALS环境变量设置为步骤1中保存的私钥文件的绝对路径。例如
export GOOGLE\u APPLICATION\u CREDENTIALS=“/Users/…/…account.json”
3) 现在运行您的仿真器firebase仿真器:开始——仅限函数
现在,本地模拟的函数了解环境。因此,当您执行类似于admin.initializeApp(functions.config().firebase)的操作时代码>正确配置它