无法使用某些奇怪的googleapis npm模块错误来部署Cloud Functions,该错误是使用官方google文档将FCM旧版迁移到V1。
这是我的package.json:
"dependencies": {
"@types/node-cron": "^2.0.0",
"@types/request-promise": "^4.1.42",
"cookie-parser": "^1.4.3",
"cors": "^2.8.5",
"cron-parser": "^2.7.3",
"express": "^4.16.4",
"firebase-admin": "~7.0.0",
"firebase-functions": "^2.2.0",
"googleapis": "^40.0.0",
"request": "^2.88.0",
"request-promise": "^4.2.2"
},
"devDependencies": {
"tslint": "^5.12.0",
"typescript": "^3.2.2"
}
和引起问题的主要功能的内容:
return new Promise(function(resolve, reject) {
const key = require('./service-account.json');
const SCOPES = ['https://www.googleapis.com/auth/firebase.messaging'];
const jwtClient = new google.auth.JWT(
key.client_email,
undefined,
key.private_key,
SCOPES
);
jwtClient.authorize(function(err: any, tokens: any) {
if (err) {
reject(err);
return;
}
resolve(tokens.access_token);
});
});
给出阻止部署的控制台问题:
Function failed on loading user code. Error message: Code in file lib/index.js can't be loaded.
Is there a syntax error in your code?
Detailed stack trace: /user_code/node_modules/googleapis/build/src/googleapis.js:93
async discoverAsync(url) {
^^^^^^^^^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/node_modules/googleapis/build/src/index.js:19:22)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/user_code/lib/index.js:16:22)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
答案 0 :(得分:0)
此问题是由Cloud Functions中的Node的旧版本引起的,已更新为8个已解决的错误。