Reputation: 41
I'm writing firebase cloud function:
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
My function with name getContactObject is located in src folder of the project, and its using es6 import/export
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),
}
}
How can i use it in my firebase cloud function, that's using node js 8?
Is it possible to import getContactObject function without rewriting it?
Now i'm having errors about imports:
Upvotes: 2
Views: 898
Reputation: 1309
You have two options:
import { getCurDateWithUser } from '../../../../../../utilities/date/getCurDateWithUser'
to
const getCurDateWithUser = require('../../../../../../utilities/date/getCurDateWithUser')
tsconfig.json
make sure to set {
//...
"compilerOptions": {
//..
"module": "commonjs"
}
}
Upvotes: 1