我具有2个HTTP功能。部署到云时,它运行良好。但是对于开发,当我尝试用
为当地服务时 firebase serve --only functions
我遇到了这个错误,
ERROR: Function load error: Code could not be loaded.
ERROR: Does the file exists? Is there a syntax error in your code?
ERROR: Detailed stack trace: /home/saiy2k/projects/ionic/grcloud/functions/node_modules/@google-cloud/common/src/util.js:545
throw util.missingProjectIdError;
^
Error: Sorry, we cannot connect to Google Cloud Services without a project ID. You may specify one with an environment variable named "GCLOUD_PROJECT". See https://googlecloudplatform.github.io/google-cloud-node/#//docs/guides/authentication for a detailed guide on creating an authenticated connection.
at Object.<anonymous> (/home/saiy2k/projects/ionic/grcloud/functions/node_modules/@google-cloud/common/src/util.js:54:29)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/saiy2k/projects/ionic/grcloud/functions/node_modules/@google-cloud/common/src/service.js:30:12)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/saiy2k/projects/ionic/grcloud/functions/node_modules/@google-cloud/common/src/grpc-service.js:38:15)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
⚠ functions: Failed to emulate handlePayment
⚠ functions: Failed to emulate testHTTPListener
i functions: No HTTPS functions emulated. Support for other function types are coming soon.
尝试设置这样的env变量, firebase functions:config:set GCLOUD_PROJECT="gr-staging"
但是有一个错误:Error: Invalid config name GCLOUD_PROJECT, cannot use upper case.
查看此页面:https://firebase.google.com/docs/functions/local-emulator还有其他需要照顾的,可以在本地服务HTTP功能吗?
Firebase CLI:v3.10.1我的package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"@google-cloud/storage": "^0.4.0",
"child-process-promise": "^2.2.0",
"firebase-admin": "~4.2.1",
"firebase-functions": "^0.5.9",
"mkdirp": "^0.5.1",
"mkdirp-promise": "^4.0.0",
"moment": "^2.18.1",
"request": "^2.81.0",
"request-promise": "^4.2.1",
"typescript": "^2.4.2"
},
"private": true,
"devDependencies": {
"ts-loader": "^2.3.2",
"webpack-node-externals": "^1.6.0"
}
}
的价值,这绝不是一个很好的解决方案,但它有效。
在第545行上的/home/saiy2k/projects/ionic/grcloud/functions/node_modules/@google-cloud/common/src/util.js
中评论throw
,这导致错误不会对我可以收集的模拟器造成不良影响。
在我的情况下,所有检查功能正在接收的所有对象都是未定义的,或者是无效的,因此在不返回堆栈的情况下,我对这个hack感到满意,让我回到路上!