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

Error: TypeError: undefined is not an object (evaluating 'import_util.inspect.custom') #345

Open kamph488 opened 2 months ago

kamph488 commented 2 months ago

I'm running into this error each time and can't figure out what the problem is.

TypeError: undefined is not an object (evaluating 'import_util.inspect.custom')

I've created the following code:


import React from 'react';
import { createMollieClient } from '@mollie/api-client';

const PaymentButton: React.FC = () => {
  const handleClick = async () => {
    try {
      const mollie = createMollieClient({ apiKey: 'test_xxxxx' });

      const payment = await mollie.payments.create({
        amount: {
          currency: 'EUR',
          value: '10.00'
        },
        description: 'Testbetaling',
        redirectUrl: 'https://example.com/redirect'
      });

      console.log('Payment created:', payment);
      // Voer hier eventuele verdere acties uit, bijvoorbeeld het doorsturen van de gebruiker naar de betaalpagina
    } catch (error) {
      console.error('Error creating payment:', error);
      // Voer hier eventuele foutafhandeling uit
    }
  };

  return (
    <button onClick={handleClick}>Doe een betaling</button>
  );
};

export default PaymentButton;

Of course with a test api key from Mollie. When I comment out the lineconst mollie = createMollieClient({ apiKey: 'test_xxxxx' }); the error is gone..

Please help.

fjbender commented 2 months ago

Your const PaymentButton has me worried you're doing something potentially dangerous, ie. exposing your API Key to the Client. I recommend you review https://github.com/mollie/mollie-api-node?tab=readme-ov-file#a-note-on-use-outside-of-nodejs.

I recommend the following: