Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error in sample sendgrid node.js code, during run time. #429

Closed
kiranshashiny opened this issue Aug 29, 2017 · 4 comments
Closed
Labels
status: help wanted requesting help from the community type: question question directed at the library

Comments

@kiranshashiny
Copy link

kiranshashiny commented Aug 29, 2017

Issue Summary

I am getting a Syntax error in mail.js when I copied the sample sendgrid code and tried to run it on my server

Steps to Reproduce

  1. npm install @sendgrid/mail
  2. exported environment variable SENDGRID_API_KEY in my bash environment
  3. Copied the sample code
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
  to: 'test@example.com',
  from: 'test@example.com',
  subject: 'Sending with SendGrid is Fun',
  text: 'and easy to do anywhere, even with Node.js',
  html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
sgMail.send(msg);

Last step:
Run the code

# node sendgrid.js
/root/scripts/node_modules/@sendgrid/mail/src/mail.js:6
const {
      ^

SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/root/scripts/sendgrid.js:1:78)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

Technical details:

# npm list |grep sendgrid
├─┬ @sendgrid/mail@6.0.0
│ ├─┬ @sendgrid/client@6.0.0
│ │ ├── @sendgrid/helpers@6.0.0 deduped
│ └─┬ @sendgrid/helpers@6.0.0
├─┬ sendgrid@5.2.3
│ └── sendgrid-rest@2.4.0
npm ERR! extraneous: assert-plus@1.0.0 /root/scripts/node_modules/jsprim/node_modules/assert-plus
npm ERR! extraneous: assert-plus@1.0.0 /root/scripts/node_modules/verror/node_modules/assert-plus
npm ERR! extraneous: assert-plus@1.0.0 /root/scripts/node_modules/dashdash/node_modules/assert-plus
npm ERR! extraneous: assert-plus@1.0.0 /root/scripts/node_modules/getpass/node_modules/assert-plus
npm ERR! extraneous: assert-plus@1.0.0 /root/scripts/node_modules/sshpk/node_modules/assert-plus
# npm -v 
5.3.0
# node -v
v4.8.4
# echo $SENDGRID_API_KEY
SG.jyr8dVjFTBO4MayuTAS_zA.7a9Qg_XXXXXX
@thinkingserious thinkingserious added status: help wanted requesting help from the community status: work in progress Twilio or the community is in the process of implementing labels Aug 29, 2017
@thinkingserious
Copy link
Contributor

Hello @kiranshashiny,

I believe this is not working for you because v6 of this SDK does not support Node v4.

Do you have access to a machine that uses Node v6 or higher?

With Best Regards,

Elmer

@thinkingserious thinkingserious added type: question question directed at the library and removed status: work in progress Twilio or the community is in the process of implementing labels Aug 29, 2017
@adamreisnz
Copy link
Contributor

This is correct, the error is happening on a destructuring statement which is not supported in Node 4.

@kiranshashiny
Copy link
Author

I upgraded to node 8.x and it works.

@kiranshashiny
Copy link
Author

Closing the issue as the fix was to upgrade.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: question question directed at the library
Projects
None yet
Development

No branches or pull requests

3 participants