wallinglee
(Charlie Walling)
October 31, 2023, 11:30pm
1
Getting this error when trying to start my server and connect to mongodb.
I have Node v21.1.0 installed. Anyone fixed this error before?
node_modules\bson\lib\bson.cjs:479
inspect ??= defaultInspect;
^^^
SyntaxError: Unexpected token '??='
3 Likes
I was facing the same issue.
As a workaround, I integrated docker to my NodeJS application and used the latest stable version of Node (18.12.0). That solved the problem so I am guessing the issue stems from using Node v21
wallinglee
(Charlie Walling)
November 1, 2023, 11:51am
3
I don’t think so. I was using v18 and still had the same issue. I read another post that said upgrading node to the latest was the fix. It wasn’t.
alexbevi
(Alex Bevilacqua)
November 1, 2023, 4:59pm
4
@wallinglee we saw a similar question when 6.0.0 of the driver was released (MongoDB NodeJS Driver 6.0.0 Released - #3 by Warren_James ) .
The nullish coalescing assignment has been supported since Node.js 15, so it would be worth verifying that you’re indeed running your code in the version of the runtime you’ve indicated.
If you add a console.log(process.version)
to the code this should be fairly easy to validate.
wallinglee
(Charlie Walling)
November 1, 2023, 6:04pm
5
Nothing logs because the error happens.
alexbevi
(Alex Bevilacqua)
November 1, 2023, 6:17pm
6
If you tried the same test using Node.js 21 (via docker) does the issue still occur?
wallinglee
(Charlie Walling)
November 1, 2023, 6:41pm
8
node -v
v18.12.0
console.log(process)
process: process {
version: 'v14.18.0',
versions: {
node: '14.18.0',
alexbevi
(Alex Bevilacqua)
November 1, 2023, 7:08pm
9
@wallinglee , based on your process
output you’re still running Node 14 - even if you have Node 18 available.
I’m not sure how you’re starting your server, but it appears an older version of Node is being used here.
wallinglee
(Charlie Walling)
November 1, 2023, 8:02pm
10
I just use npm run start in my node express app.
"start": "node index.js"
Yeah, it appears to be a node version error. I switched from v14.21.3 to v18.2.0 and then it worked fine.
1 Like
wallinglee
(Charlie Walling)
November 1, 2023, 8:59pm
12
I’ve tried several node version installs. None fix the issue
Its not a Node Issue, its issue with mongoose V-8 and above, if you use mongoose V-7.4.1 then problem will be solve.
3 Likes
Juanpi_N_A
(Juanpi N/A)
November 4, 2023, 8:34pm
14
I’m getting a similar error. Tried downgrading mongoose to the version you specified, but it keeps happening.
Any workaround?
SyntaxError: Unexpected identifier
I was facing the same issue and after trying different approaches, the one that worked for me was using mongoose version 7.6.3
So in your server, run the command: npm i mongoose@7.6.3
It worked for me. Hopefully, it does for you too
Try using mongoose version 7.6.3 instead of the latest one. It worked for me :>
Buki_John
(Buki John)
November 7, 2023, 9:35am
17
Thank’s! It’s work for me to!
Moving to version 7.6.3 worked ! Thanks
The version 8 was working locally for me but when I tried to deploy to render it didnt work
But 7.6.3 worked thanks!
PT-BR: Isso deu certo obrigado
EN: this worked thank you