node.js - 部署 Google Cloud Task Client 时出错
问题描述
我正在尝试使用 Google Cloud Tasks 创建任务,但遇到错误。
我的代码可以完美编译,但是当它到达 Cloud Tasks 初始化行时:
const data = snap.data();
let expirationInSeconds
if(data.booking_date_ts - Date.now() > 172800000){
expirationInSeconds = (Date.now() + 172800000) / 1000
}else{
expirationInSeconds = (Date.now() + 180000) / 1000
}
const project = JSON.parse(process.env.FIREBASE_CONFIG).projectId
const location = 'us-central1'
const queue = 'reminders'
const tasksClient = new CloudTasksClient() // This is the error line
const queuePath = tasksClient.queuePath(project, location, queue)
const url = `https://${location}-${project}.cloudfunctions.net/bookingExpirationCallback`
const docPath = snap.ref.path
const payload = { docPath }
const task = {
httpRequest: {
httpMethod: 'POST',
url,
body: Buffer.from(JSON.stringify(payload)).toString('base64'),
headers: {
'Content-Type': 'application/json',
},
},
scheduleTime: {
seconds: expirationInSeconds
}
}
return await tasksClient.createTask({ parent: queuePath, task });
我收到以下错误:
错误:Node.js v10.0.0 是最低要求
这很奇怪,因为他们的文档说:
我们的客户端库遵循 Node.js 发布时间表。库与 Node.js 的所有当前活动和维护版本兼容。
我当前的 Node.js 版本是:v12.16.3
解决方案
问题是我的 Node.js 版本设置为 12.16.3,但 process.version 是 8.3.2。
如何解决?
修改 package.json 引擎:
"engines": {
"node": "8"
},
至
"engines": {
"node": "10"
},
推荐阅读
- clang - 编写 AST 匹配器以查找所有没有 break 语句的 case 语句
- amazon-web-services - AWS负载均衡器监听器添加后消失
- matlab - 如何重载 Matlab 运算符以便将元素明智地应用于对象数组
- java - 如何仅使用数组中数字大于 X 的文档制作 RecyclerView
- php - 如何使我的锚标记从我的表中传输信息?
- xml - 如何在 Python 中将 `lxml.etree` 之类的东西应用于 RDD?
- java - 在 Apache Beam 管道中结合 Java 和 Python
- c# - 为什么 Xamarin.Forms 设计器不显示窗口布局?
- c - 我有一个 adj 矩阵图,我想知道如何从特定顶点遍历到另一个特定顶点
- python-3.x - soup.find_all 返回空列表