'X Is not a function' in CommonJS

Issue

I’ve got the following code I transformed from a Trypescript, ESM-syntax based file to a Javascript, CJS-syntax file.

const apiClientFactory = require("@vue-storefront/core");

function onCreate(settings) {
  return {
    config: settings,
    client: {},
  };
}

const getPrice = () => {
  console.log("$55,98")
}

const { createApiClient } = apiClientFactory({
  onCreate,
  api: {
    getPrice,
  },
});

module.exports = {
  createApiClient,
};

I can not seem to find if the error "apiClientFactory is not a function" originates from old ESM-based code. Or that the function isn’t called properly. However, apiClientFactory is correctly imported (ESM syntax)

Solution

What are you trying to achieve with this?

Because the whole Vue Storefront project uses TypeScript, so I recommend you to use it and follow the procedures and code standards that we are using.

To find a good example on the API please check the code for the integrations of Magento or Vendure.

Also, I want to invite you to our Discord server at https://discord.gg/vuestorefront

Answered By – Heitor

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.