云功能无法部署一些奇怪的googleapis npm模块错误,正在使用官方的Google Docs迁移FCM遗产为V1。
这是我的软件包。
"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)
问题是由云功能中的旧版本引起的,更新为8个解决错误。