Google Cloud Functions 部署问题
Posted
技术标签:
【中文标题】Google Cloud Functions 部署问题【英文标题】:Google Cloud Functions deploy issue 【发布时间】:2019-10-06 07:00:56 【问题描述】:Cloud Functions can't be deploying 一些奇怪的 googleapis npm 模块错误,正在使用官方 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)
【问题讨论】:
请编辑问题以显示您的 package.json 的内容。 您要求函数以什么版本的 javascript / Node.js 运行? @Kolban 嗯,这可能是问题所在,Cloud Functions 上安装了 Node 6 【参考方案1】:该问题是由 Cloud Functions 中的旧版本 Node 引起的,更新到 8 已解决错误。
【讨论】:
以上是关于Google Cloud Functions 部署问题的主要内容,如果未能解决你的问题,请参考以下文章
使用TensorFlow作为依赖项部署Google Cloud Functions
在本地测试 Python Google Cloud Functions
Google Cloud Platform:Cloud Functions 与 App Engine
Google Cloud Functions Deploy“允许未经身份验证的调用......”
为啥我的函数没有部署到 Google Cloud Platform?
如何使用 Google Python Client for Cloud Functions 获取 Google Cloud Functions 列表?