mailjet-apiv3-nodejs icon indicating copy to clipboard operation
mailjet-apiv3-nodejs copied to clipboard

cant use .connect or .apiconnect

Open HEIN390 opened this issue 3 years ago • 6 comments

const Mailjet = require('node-mailjet'); const mailjet = Mailjet.apiConnect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE);

I always receive errors like "Mailjet.apiConnect is not a function" or "Mailjet.connect is not a function"

HEIN390 avatar Jul 19 '23 14:07 HEIN390

Hi, @xXTim97Xx can you share a bit more context on the environment you're using? Node version, library version etc.

ai-wintermute avatar Jul 21 '23 10:07 ai-wintermute

Node Version: 15.8.0 React: 17.0.1 node-mailjet: 6.0.3

HEIN390 avatar Jul 22 '23 11:07 HEIN390

image

You can also check my IntelliSense that it really is not shown here

HEIN390 avatar Jul 22 '23 15:07 HEIN390

So you're trying to use require in the client's code? You can't do this as it's part of the node CommonJS module system. Can you use import instead? As described here: https://github.com/mailjet/mailjet-apiv3-nodejs#send-email-example

ai-wintermute avatar Jul 23 '23 09:07 ai-wintermute

Yes, thanks a lot. This seems to work that way. But how do I use the proxy hack for testing?

I'm always receiving a CORS Error now

HEIN390 avatar Jul 23 '23 10:07 HEIN390

@xXTim97Xx it's because you need to set up your headers correctly to allow these cross-origin requests. You can read about them here: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

ai-wintermute avatar Jul 24 '23 08:07 ai-wintermute