mollie-api-node: Client fails to import pem file on AWS lambda

Because of a known problem with the __dirname variable in serverless lambda functions, it is not possible to use the mollie-api-node module in a serverless environment.

See: https://github.com/serverless/serverless/issues/4778

A possible fix would be to inline the pem file as part of the build process of the module, or somehow work around using __dirname in /dist/mollie.js on line 35:

options.httpsAgent = new https.Agent({
    cert: fs.readFileSync(path.resolve(__dirname, cert))
});

If you have any other solutions for this issue, I would be glad to hear about it

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17

Most upvoted comments

@JoschuaSchneider We have been dabbling with the idea of bundling the certificates into the JavaScript file. This should fix this issue. (See https://github.com/mollie/mollie-api-node/commit/966044314aca0810b918756e503e03b199d85f6f if you are interested.)

I will bring this up internally once again and keep you posted.

This should be fixed in version 3.2.4.

@edblocker I originally wanted to create a pull request but then I ended up using just this one simple function instead of the whole library. This is way easier than modifying the whole library. Take a look at the code snippet i posted here, I am sure it will help you: https://github.com/mollie/mollie-api-node/issues/105#issuecomment-605466479

i changed a few small things in their config files and finally got their module bundler to inline the .pem file enjoy: https://github.com/smonist/mollie-api-node-inline-pem

nope, not yet. but i will propably create a fork tomorrow 😃

i ran into the same problem yesterday - i fixed it by using raw-loader and replacing the fs.readFileSync(path.resolve(__dirname, cert)) call with a require at the top of the file. its a quick workaround, if there are better solutions please let me know!