sendgrid / sendgrid-nodejs

The Official Twilio SendGrid Led, Community Driven Node.js API Library
https://sendgrid.com
MIT License
2.98k stars 781 forks source link

Issue with FS dependency #382

Closed bissolli closed 7 years ago

bissolli commented 7 years ago

Hey guys!

I have a application built on webpack and VueJS2! I am trying to use this library to send email through sendgrid and I have the following problem:

This dependency was not found:
* fs in ./~/sendgrid/lib/helpers/inbound/parse.js, ./~/mime/mime.js and 1 other
To install it, you can run: npm install --save fs

I've already run npm install --save fs and it's still same problem!

It's a client application... could be that the problem?

thinkingserious commented 7 years ago

Hello @gustavobissolli,

Ah yes, fs in not allowed in the browser. We need to figure out a way to not include that dependency when used on the client side. I've added this to our backlog for further investigation.

Thanks!

Elmer

bissolli commented 7 years ago

Understand @thinkingserious!

Do you know an alternative way to send emails by the client side?

thinkingserious commented 7 years ago

@gustavobissolli,

Can you try deleting this folder? https://github.com/sendgrid/sendgrid-nodejs/tree/master/lib/helpers/inbound

bissolli commented 7 years ago

Unfortunately still not working =/

This relative module was not found:

* ./lib/helpers/inbound/parse.js in ./~/sendgrid/index.js

I guess for while I should send an Ajax request to my server service to do it through my php api...

thinkingserious commented 7 years ago

You can try deleting this line also: https://github.com/sendgrid/sendgrid-nodejs/blob/master/index.js#L4

If you choose the PHP route, you can use: https://github.com/sendgrid/sendgrid-php

bissolli commented 7 years ago

@thinkingserious great! Looks we get a step forward now =)

I have the following error about my request:

Fetch API cannot load https://api.sendgrid.com/v3/mail/send. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://sendgrid.api-docs.io' that is not equal to the supplied origin. Origin 'http://localhost:8181' is therefore not allowed access. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Could be that something related to the inbound parser or FS package missing?

thinkingserious commented 7 years ago

It seems that this is your issue now: https://sendgrid.com/docs/Classroom/Basics/API/cors.html

bissolli commented 7 years ago

Hmmm it make sense! I can't protect my API Key on a browser based application and SendGrid refuse my api call based on it!

I am going to make an end point on my API to do that job!

Thanks for the help @thinkingserious

thinkingserious commented 7 years ago

Awesome! Please let me know if you run into any issues with developing the endpoint.

olaven commented 5 years ago

If I am not mistaken, this still appears to be an issue: #955 Or at least something like it 😄

For anyone coming here, this workaround from @nephlin7 worked for me:

// In webpack config 
node: {
      net: 'empty',      
      fs: 'empty',
      tls: 'empty'
}