mailjet / mailjet-apiv3-nodejs

[API v3] Official Mailjet API v3 NodeJS wrapper
https://dev.mailjet.com
MIT License
235 stars 69 forks source link

Error while loading in Cloudflare Workers #230

Closed nileshtrivedi closed 1 year ago

nileshtrivedi commented 1 year ago

I get the following error with require('node-mailjet') within a Cloudflare Worker:

notes: [
      {
        text: 'Uncaught ReferenceError: define is not defined\n' +
          '  at index.js:19:5 in node_modules/node-mailjet/mailjet.web.js\n' +
          '  at index.js:6:50 in __require\n' +
          '  at index.js:2129:15\n' +
          ' [code: 10021]'
      }
    ],

As you can see, it's loading mailjet.web.js and not mailjet.node.js. This is probably because, as Cloudflare Docs say:

Many packages that require Node dependencies, such as fs or net/http, aren't supported in Workers because Workers isn't Node—it's built on V8

It would be great to be able to use this library in Cloudflare Workers environment.

nileshtrivedi commented 1 year ago

This happens even when I use the --node-compat flag for Node compatibility with my wrangler command.

haydencleary commented 1 year ago

Having the same issue here 🙋‍♂️ @nileshtrivedi did you find a work-around or a different service ? In my current situation this makes Mailjet unusable for me.

nileshtrivedi commented 1 year ago

@haydencleary I ended up keeping MailJet but switched to Netlify Functions instead of Cloudflare which is a very unique environment.

haydencleary commented 1 year ago

Ah right, fair enough! I can't change environments sadly. I have an a Shopify app deployed on their Oxygen architecture which is based on Cloudflare. Not much is compatible with their workers at the moment ... 🥲

ai-wintermute commented 1 year ago

Hi @nileshtrivedi sorry for the long response. Unfortunately, we are not going to support Cloudflare workers in the nearest versions. But you are always welcome to suggest your features/improvements by creating a pull request to the library.