ServerMiddleware Error: Unexpected token ‘&&=’

The following line in my Nuxt server middleware throws a syntax error:

query._id &&= new mongo.ObjectId(query._id)
ERROR  ServerMiddleware Error: Unexpected token '&&='

query._id &&= new _mongoose.mongo.ObjectId(query._id);
^^^

As far as I know the logical AND assignment operator (&&=) is valid Javascript syntax. If I rewrite this line to

query._id = query._id && new mongo.ObjectId(query._id)

it works.

Answer

This kind of operator is only available in Node v15+ versions as told here: https://medium.com/nerd-for-tech/the-difference-between-and-operators-in-javascript-nodejs-3696b0ce02ff

Because yeah, the new things usually take a bit more time to come to the backend than the front-end.

You’re probably running on the latest LTS aka v14, type node -v to be sure.