How to correctly import a module dynamically and use a function from it?

68 views Asked by At

I am importing got dynamically, like this:

  const { default: moduleGot } = await import('got');
  moduleGot();

Then, I want to execute a function from it:

const response = await got(url, {
  method: 'POST',
  headers: {
    "Content-Type": `multipart/form-data; boundary=${data._boundary}`,
    "Authorization": `Bearer ${config.pinata.jwt}`
  },
  body: data
})

But I am getting ReferenceError: got is not defined

What is the right way of importing it and then use got?

0

There are 0 answers