altruistic altruistic - 1 month ago 9
Node.js Question

Connect-mongo Syntax Error: unexpected token =>

Hi I have the following error

node_modules/connect-mongo/src/index.js:29
unserialize: options.unserialize || (x => x),
^^


I have these versions:

node@v3.3.1

express@4.14.0

mongoose@4.6.5

mongodb@2.2.11

Answer

Most probably you have an outdated version of Node.js.

The (x => x) is equivalent with function (x) { return x; } (it's called an arrow function).

Update Node.js to a version greater than 4.0.0.

Running the node process with the --harmony flag could solve the issue, but still updating the Node.js to a recent version is much better.