"SyntaxError: Unexpected token )" in Node.js
Asked Answered
S

1

5

I keep getting a SyntaxError: Unexpected token )' error for the following code:

passport.use(
  'local-signup',
  new LocalStrategy({
      usernameField: 'email',
      passwordField: 'password',
      passReqToCallback: true, // pass back req to callback
    },
    (req, email, password, done) => {
      // ...
    },
  ),
);

It really only started after I put arrow functions in. I think I'm missing something syntax-wise. I'm using the airbnb style guide & linter btw. Running Node.js LTS. VS Code doesn't give any parsing errors either in the editor itself. The code works when transpiled to ES2015 via Babel. I'm still curious why it isn't working with the ES6 syntax.

Spade answered 4/6, 2017 at 13:48 Comment(0)
M
7

The problem is that in two places you're using a trailing comma in function syntax, i.e. a comma after the last argument of a function.

passport.use(
  'local-signup',
  new LocalStrategy({
      usernameField: 'email',
      passwordField: 'password',
      passReqToCallback: true, // pass back req to callback
    },
    (req, email, password, done) => {
      // ...
    },
//   ^
  ),
// ^
);

This syntax is part of ECMAScript 2017, and is not supported by Node.js before version 8.0.0, but can be transpiled using Babel.

Mog answered 4/6, 2017 at 13:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.