Javascript 如何在firebase云函数中包含带导入的js函数?
我正在编写firebase云函数:Javascript 如何在firebase云函数中包含带导入的js函数?,javascript,node.js,firebase,google-cloud-functions,Javascript,Node.js,Firebase,Google Cloud Functions,我正在编写firebase云函数: const {getContactObject} = require('../../../../src/modules/Contacts/scenes/Contactlist/ContactsManager/functions/getContactObject') const getApiResponsible = require('../../functions/getApiResponsible') const createContact = asyn
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),
}
}
我如何在firebase云函数中使用它,即使用NodeJS8
是否可以导入getContactObject函数而不重写它
现在我在导入方面出现错误:
您有两个选择:
从'../../../../../../../utilities/date/getCurDateWithUser'导入{getCurDateWithUser}
到
const getCurDateWithUser=require('../../../../../../../utilities/date/getCurDateWithUser')
tsconfig.json中,确保设置
{
//...
“编译器选项”:{
//..
“模块”:“commonjs”
}
}
这似乎很相似:请尝试删除卷曲的bruckets和getCurDateWithUser
之间的空格,这样就好像从导入{getCurDateWithUser}。让我知道这是否有帮助。