javascript - 如何在 firebase 云函数中包含 js 函数和导入?
问题描述
我正在编写firebase云功能:
const {getContactObject} = require('../../../../src/modules/Contacts/scenes/Contactlist/ContactsManager/functions/getContactObject')
const getApiResponsible = require('../../functions/getApiResponsible')
const createContact = async payload => {
console.log('payload', payload)
console.log(getContactObject(getApiResponsible()))
}
module.exports = createContact
我的函数名为getContactObject位于项目的 src 文件夹中,它使用 es6 导入/导出
getContactObject.js
import { getCurDateWithUser } from '../../../../../../utilities/date/getCurDateWithUser'
export const getContactObject = uid => {
return {
lastName: '',
name: '',
middleName: '',
gender: '',
phone: [],
email: [],
messangers: [],
social: [],
address: [],
dates: [],
leads: [],
sales: [],
responsible: '',
created: getCurDateWithUser(uid),
updated: getCurDateWithUser(uid),
}
}
我如何在使用节点 js 8 的 firebase 云功能中使用它?
是否可以在不重写的情况下导入getContactObject函数?
现在我遇到了关于导入的错误:
解决方案
你有两个选择:
- 重写以下行:
import { getCurDateWithUser } from '../../../../../../utilities/date/getCurDateWithUser'
至
const getCurDateWithUser = require('../../../../../../utilities/date/getCurDateWithUser')
- 使用打字稿。在你
tsconfig.json
确保设置
{
//...
"compilerOptions": {
//..
"module": "commonjs"
}
}
推荐阅读
- python - 如何在 Airflow 中将 DatabaseHook 对象与 PythonOperator 一起使用而不会耗尽连接?
- amazon-web-services - 您可以运行具有多个前缀的 S3 API 请求吗?
- svg - 使用嵌入的 PNG/JPG 打印宽 SVG 图像
- woocommerce - knockoutJS 订阅 observable
- java - 百里香叶值到 html 选择输入
- javascript - javascript获取带有URL的输入变量以执行发布到URL
- r - Normalization/transformation prior to PCA with Box-Cox
- java - 硬重启后json为空
- python - python在简单国际象棋程序中跳过代码的问题
- scripting - 从脚本创建 PSQL 数据库