'use latest' isn't giving me ES6 features importing nodemailer


#1

Hey!
Trying to setup a function to send an email using nodemailer, I saw the package used ES6 features, so I added ‘use latest’ to get them.

'use latest'
const nodemailer = require('nodemailer');

module.exports = function (event) {
  console.log(event.data)
  return {data: event.data}
}

However, this gives me:

SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Module._compile (/data/sandbox/lib/module.js:127:21)
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> (/data/_verquire/nodemailer/4.1.0/node_modules/nodemailer/lib/nodemailer.js:3:16)
at Module._compile (module.js:409:26)

What am I doing wrong here?
Thanks!


#2

use latest only applies to your own code, not to modules you require. You need to require a compatible version of nodemailer.

However, the require('nodemailer') syntax does not allow you to specify a specific version at Graphcool; require('nodemailer@2.5.0') breaks at Graphcool.

However, I found that you can use the syntax import nodemailer from 'nodemailer@2.5.0'. This actually allows you to use a nodemailer version that is compatible with Node <6.


#3

can you share your code, import gives me syntax error.