mollie-api-node icon indicating copy to clipboard operation
mollie-api-node copied to clipboard

TypeError: createMollieClient is not a function

Open DHFW opened this issue 1 year ago • 1 comments

I had my code like this, what should work according to the docs, using TypeScript: import createMollieClient, { PaymentStatus } from '@mollie/api-client';

And calling the createMollieClient code like so:

 const mollieClient = createMollieClient({
        apiKey: ...
      });

When using this with babel transpiled to CJS this worked fine (NodeJS 16.x)

I recently updated my project to Node 18.18.0, using ESBuild and ES modules as build output. At development time, TypeScript was fine with this.

But when running the code, it raised this error: TypeError: createMollieClient is not a function. After some investigation I saw that the createMollieClient is export as default and as names export, so I tried the import like so:

import {createMollieClient, PaymentStatus } from '@mollie/api-client';

And that worked (notice the named import instead the default export). I has something to do with the way the code is exported and build.

I'm not sure how this is possible, but leaving this here to maybe save others some time...

DHFW avatar Dec 27 '23 13:12 DHFW