2

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:

Errors log

2
  • This seems similar: stackoverflow.com/questions/51564072/node-js-unexpected-token Commented Mar 12, 2020 at 13:51
  • Please try removing the spaces between the curly bruckets and the getCurDateWithUser so it would be like import {getCurDateWithUser} from. Let me know if this helps. Commented Mar 13, 2020 at 13:15

1 Answer 1

1

You have two options:

  1. Rewrite the following line:
import { getCurDateWithUser } from '../../../../../../utilities/date/getCurDateWithUser'

to

const getCurDateWithUser = require('../../../../../../utilities/date/getCurDateWithUser')
  1. Use Typescript. In your tsconfig.json make sure to set
{
  //...
  "compilerOptions": {
        //..
        "module": "commonjs"
  }
} 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.