Spread arrow function spread argument Unexpected token ...error


#1

Hello,

I have a problem, I’ve imported a new package in my project and it seems to be the first (for me) that uses the spread operator as arguments in a arrow function declaration.

/mnt/sda3/www/…/src/node_modules/nodemailer/lib/mailer/index.js:31
W20170415-21:04:48.736(3)? (STDERR) compile: [(…args) => this._convertDataImages(…args)],
W20170415-21:04:48.736(3)? (STDERR) ^^^

I tried installing all babel plugins I could find related to it, ofc didn’t worked or else I would be here. I only found a similar bug but was fixed in meteor 1.3
The package has a node >=6 dependency from what I can see.

Meteor 1.4.4.1

abernix:standard-minifier-js 1.3.19 Standard javascript minifiers used with Meteor apps by default.
ecmascript 0.7.3 Compiler plugin that supports ES2015+ in all .js files
es5-shim 4.6.15 Shims and polyfills to improve ECMAScript 5 support
meteor-base 1.0.4 Packages that every Meteor app needs
seba:minifiers-autoprefixer 1.0.1 Standard minifiers used with Meteor apps by default + css

├── babel-cli@6.24.1
├── babel-plugin-transform-es2015-destructuring@6.23.0
├── babel-plugin-transform-es2015-parameters@6.24.1
├── babel-plugin-transform-object-rest-spread@6.23.0
├── babel-preset-env@1.4.0
├── babel-preset-es2016@6.24.1
├── babel-preset-es2017@6.24.1
├── babel-preset-meteor@6.26.0
├── babel-preset-react@6.24.1
├── babel-preset-stage-0@6.24.1
├── babel-preset-stage-2@6.24.1
├── babel-runtime@6.23.0
├── meteor-babel@0.14.4

.babelrc (I tried more combinations, this is the final I give up version)

{
  "presets": [
    "meteor",
    "react",
    "es2015",
    "es2016",
    "es2017",
    "stage-0"
  ],
  "plugins": [
    "babel-plugin-transform-es2015-parameters",
    "transform-function-bind",
    "babel-plugin-transform-object-rest-spread",
    "transform-es2015-destructuring"
  ],
  "retainLines": true
}

#2

Same issue here. Spent 2 days trying all kinds of configs to work around.
Trying at present to configure meteor to use babel-node instead of node, but no luck so far.

My code runs fine using babel-node, but the …args barf is ruining my weekend.

Any progress?


#3

Not yet, I gave up and put the task on hold. Hopefully would be fixed on a next Babel version.


#4

The current version of nodemailer requires nodejs v6 - which natively supports some ES6/7 operations which were polyfilled (one of which is the spread operator).

For nodejs v4 (which is Meteor’s current version), the polyfills have to be used.

npm packages are built when they are installed (e.g. with meteor npm i --save). So, the correct time to implement the polyfills is at package installation time - that means declaring the correct babel controls in the package’s package.json. The built module will then be compatible with nodejs v4. Given that the package author has specified nodejs v6, that’s unlikely to happen.

There are some ways you could address this:

  1. Clone the package and put the required babel controls in.
  2. Extract the required module(s) from node_modules/nodemailer/ and put them into Meteor’s /imports/server/ folder, where they will be built by Meteor.
  3. Try the latest Meteor 1.6 release candidate, which uses nodejs v8 (at the time of writing that would be meteor update --release 1.6-beta.2). Ensure you back up your project first!

#5

npm packages are built when they are installed

This, this … ofc, I will write on a post it so never forget it again. Thanks sir!
While looking trough trough the microscope I forgot about the telescope.


#6

Downgrading one version: meteor npm install --save nodemailer@2.2 worked for me.
More details:
https://community.nodemailer.com/category/releases/