Error: SyntaxError: unexpected token?

the error i am getting is:

/rbd/pnpm-volume/5e058551-ddb9-482f-9d67-f90385378863/node_modules/discord.js/src/rest/RESTManager.js:32
    const token = this.client.token ?? this.client.accessToken;
                                     ^
SyntaxError: Unexpected token ?
    at Module._compile (internal/modules/cjs/loader.js:703:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/rbd/pnpm-volume/5e058551-ddb9-482f-9d67-f90385378863/node_modules/discord.js/src/client/BaseClient.js:4:21)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)

What can I do to resolve this?

Hi, welcome @Austin_Westphal

That looks like C# syntax for the null-coalescing operator. In JavaScript, you’d use || instead.

So please try

const token = this.client.token || this.client.accessToken;

Hope it helps :slight_smile:

@SteGriff nullish coalescing is actually supported in js, but it’s a relatively new feature and works differently to the logical or.
@Austin_Westphal can you make sure you’re using node v14 or above? In your package.json, add the following:

"engines": { 
  "node": "14.x"
}

However it looks like you’re probably using discord.js v13, so you’ll need to use node 16 instead.
Happy Glitching!

1 Like

Well, TIL

Thanks Pufferfish :slight_smile:

still getting same error

@Austin_Westphal If it’s a public project, can you tell us your Glitch project name?

Just noticed that the error is inside module code, not user code… this is not my finest hour :joy:

1 Like

The Project name is enthusiastic-run-avenue