I have this error while using mongoose:
/var/www/node-api/node_modules/mongoose/node_modules/mongodb/lib/admin.js:62
session: options?.session,
^
SyntaxError: Unexpected token '.'
I reinstalled node_modules but I always get the same problem.
For mongoose and my connection in my device it worked correctly.
2
Answers
Adding an answer for this because it keeps coming up.
Problem:
Mongoose uses the MongoDB native Node.js driver as one of it’s dependencies.
In the mongodb V6 native driver they implemented optional chaining in the
async command()
withinadmin.js
:The problem is that optional chaining wasn’t supported in Node.js until V14.5.
Solution:
You need to upgrade your Node.js version to a newer version. At the current time of writing, Node V20 is the LTS so I would reccomed upgrading to that or see the Release Schedule to plan ahead.
ok, so what is the answer to fix this? I have node v21 and still getting this error