mollie / mollie-api-node

Official Mollie API client for Node
http://www.mollie.com
BSD 3-Clause "New" or "Revised" License
228 stars 62 forks source link

TypeError: createMollieClient is not a function #339

Open DHFW opened 6 months ago

DHFW commented 6 months ago

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...

Pimm commented 1 week ago

Thanks, Didier!

We will look into the optimal experience we can deliver for both CJS and ESM in the future.