mollie / mollie-api-node

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

No matching export in "node-modules-polyfills:url" for import "URL" #268

Closed binajmen closed 2 years ago

binajmen commented 2 years ago

Hi,

I'm using Remix (https://remix.run) with Mollie. I have this error while building my app.

Not sure to understand where the error come from. Are you relying on polyfills I should add to my dependencies?

[1] ✘ [ERROR] No matching export in "node-modules-polyfills:url" for import "URL"
[1] 
[1]     node_modules/@mollie/api-client/dist/mollie.esm.js:5:9:
[1]       5 │ import { URL } from 'url';
[1]         ╵          ~~~
[1] 
[1] 
[1] Build failed with 1 error:
[1] node_modules/@mollie/api-client/dist/mollie.esm.js:5:9: ERROR: No matching export in "node-modules-polyfills:url" for import "URL"

Your help would be greatly appreciated 🙏

UPDATE: my bad ;)

Pimm commented 2 years ago

This library doesn't rely on any polyfills and only depends on axios, which NPM (or Yarn) will automatically install for you.

The current version runs on Node.js 6.14.×, which has url available.

Edit: The underlying issue you're having, is that you're importing this library clientside. Frameworks such as Next.js and Remix blur the lines between clientside and serverside. It's an interesting development. However, when it comes to payments ‒ a very security-sensitive subject ‒ it is crucial that some of the logic is strictly serverside.

Specifically, it is important that your API key is never shipped to users. With this key, users will be able to act on your behalf (e.g. view the data of your customers, or create refunds). So please learn how to keep your API keys safely on your server in your framework of choice.

binajmen commented 2 years ago

This library doesn't rely on any polyfills and only depends on axios, which NPM (or Yarn) will automatically install for you.

The current version runs on Node.js 6.14.×, which has url available.

Yes it was totally my fault ;)

Pimm commented 2 years ago

No problem! I'm also commenting for the person who stumbles upon this issue.

dodas commented 2 years ago

Hey there! I'm running into the same issue (using node 14.17.3). Mind sharing how you solved it @binajmen ? Thanks.

binajmen commented 2 years ago

Hey there! I'm running into the same issue (using node 14.17.3). Mind sharing how you solved it @binajmen ? Thanks.

Hi @dodas, this problem was specific to how Remix works. If you're using Remix, you have to add the suffix .server.ts to keep things at server side.

dodas commented 2 years ago

Yes, I am using Remix. I managed to fix it in a similar manner – the package being bundled into frontend code was the problem.

Pimm commented 2 years ago

Thanks for commenting. Chances are that you're helping out the next person who finds themself in the same situation.

I'm updating my first answer to be a little more helpful.