ESN Docs

Docs › Help › Error fixes

Fix discord.js "SyntaxError: Unexpected token '?'" (Node.js too old)

1 min readUpdated Nov 4, 2026

discord.js v14 needs a modern Node.js. Old Node can't read its code and stops with "Unexpected token". Update Node and the error is gone.

The error #

/home/container/node_modules/discord.js/src/client/Client.js
      ...
            ^
SyntaxError: Unexpected token '?'

You might also see SyntaxError: Unexpected token '.', Cannot find module 'node:events' or a warning that discord.js needs a newer Node.js.

Why it happens #

discord.js v14 uses modern JavaScript (like ?? and ?.) that old Node.js versions can't read. Current discord.js v14 needs Node.js 18 or newer, and Node 22 is a safe pick. The error is common on old school or work PCs, free hosts stuck on old Node, and old VPS images.

Check your Node version #

Run this where the bot runs:

node -v

If it prints v16 or lower, that's the problem.

How to fix it #

  • On your PC: install the current LTS from nodejs.org, open a new terminal and run node -v again.
  • On ESN: open Startup → Docker Image and pick Node.js 22 or 24, then restart. ESN's Node.js bot servers already run modern versions, so this usually only happens if you picked an old image yourself.
  • On a host that can't update Node: move the bot. See move your bot to ESN.

After changing Node, delete node_modules and let npm install run again.

Don't downgrade discord.js #

Going back to discord.js v12 or v13 to fit old Node isn't worth it. Those versions use Discord's old APIs, miss slash command features and stop working as Discord changes.

FAQ #

Which Node.js version should my bot use? #

A current LTS release, such as Node.js 22. It works with discord.js v14 and gets security updates.

Can I set the Node version in package.json? #

You can add "engines": {"node": ">=18"} to warn people, but it doesn't change the Node your host runs. On ESN, pick it in Startup → Docker Image.

Does this happen with discord.py? #

The Python version is the same idea: discord.py 2.x needs Python 3.8 or newer. On ESN pick Python 3.12 or 3.13 in Docker Image.

Host your bot 24/7 from $0.50/month →

Still stuck? Use the live chat on the panel or ask in the ESN Systems Discord. Last updated November 4, 2026.