SyntaxError: Unexpected token ’{’ Error
Error Message
When running the claude command, the following error appears:
SyntaxError: Unexpected token '{'
at Loader.moduleStrategy (node:internal/modules/esm/translators:147:18)
at async link (node:internal/modules/esm/module_job:48:21)Or a similar syntax error:
SyntaxError: Unexpected token '...'
SyntaxError: Unexpected identifierRoot Cause
This error indicates your Node.js version is too old.
Claude Code uses modern JavaScript syntax features (such as object destructuring, optional chaining, and nullish coalescing operators) that require Node.js 18.x or higher.
If your system has an older version of Node.js installed (e.g., v14 or v16), syntax errors will occur when parsing the code.
Solution
Step 1: Check Your Current Node.js Version
Open PowerShell or a terminal and run:
node --versionIf the version shown is less than v18 (for example v14.17.0 or v16.13.0), you need to upgrade.
Step 2: Upgrade Node.js
Windows
Option 1: Use winget (recommended)
winget install OpenJS.NodeJSOption 2: Manual download and install
- Visit the Node.js official website
- Download the LTS (Long-Term Support) version
- Run the installer and follow the wizard to complete installation
Option 3: Use Chocolatey
choco upgrade nodejsmacOS
Using Homebrew:
brew upgrade nodeOr download manually:
Visit the Node.js official website and download the latest LTS version.
Linux
Using nvm (recommended):
nvm install --lts
nvm use --ltsUsing a package manager:
# Ubuntu/Debian
sudo apt update
sudo apt install nodejs npm
# CentOS/RHEL
sudo dnf install nodejs npmStep 3: Verify the Upgrade
After upgrading, open a new terminal window and verify the version:
node --versionEnsure the version shown is v18.x.x or higher.
Step 4: Reinstall Claude Code
If the previous installation failed, it is recommended to reinstall:
npm install -g @anthropic-ai/claude-codeThen run claude to verify it works correctly.
Note: After upgrading Node.js, globally installed npm packages may need to be reinstalled. If you encounter issues, try uninstalling and reinstalling Claude Code:
npm uninstall -g @anthropic-ai/claude-code
npm install -g @anthropic-ai/claude-codePrevention
To avoid similar issues in the future:
- Use a Node.js LTS version: LTS (Long-Term Support) versions are more stable and have better compatibility
- Keep Node.js updated: Stay on the latest LTS version
- Use a version manager: Tools like nvm (Node Version Manager) make it easy to switch between and manage multiple Node.js versions