Linux环境下Node.js运行app.js报const严格模式语法错误求助
SyntaxError: Use of const in strict mode错误 Hey there! Let's figure out how to fix that frustrating SyntaxError: Use of const in strict mode you're hitting when running app.js on Linux. I've dealt with this exact issue plenty of times, so let's break down what's going on and get your app up and running.
What's causing this?
This error almost always boils down to one thing: your Node.js version is too old. Early Node releases (like v0.10.x or v0.12.x) didn't support const outside of strict mode by default, and modern libraries like Ramda rely heavily on ES6+ features that these old versions can't handle. Even if you installed Ramda correctly, your Node runtime just doesn't know how to parse the const syntax it uses.
Step-by-step fixes
Let's go through the most reliable solutions, starting with the most recommended one:
First, check your Node.js version
Run this in your terminal to confirm what version you're working with:node -vIf the output is v0.12.x or lower, that's definitely the problem.
Upgrade Node.js to a modern LTS version
This is the permanent fix. Old Node versions are no longer supported, so upgrading will solve not just this error but future compatibility issues too. Here's how to do it on common Linux distros:- For Ubuntu/Debian-based systems:
- Remove the old Node.js and npm first:
sudo apt remove nodejs npm -y - Add the official NodeSource LTS repository:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - - Install the latest LTS Node.js:
sudo apt install nodejs -y
- Remove the old Node.js and npm first:
- For CentOS/RHEL-based systems:
- Uninstall old versions:
sudo yum remove nodejs npm -y - Add the NodeSource LTS repo:
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash - - Install Node.js:
sudo yum install nodejs -y
- Uninstall old versions:
- Alternatively, use NVM (Node Version Manager) to manage multiple versions easily:
After installing NVM, run these commands to get the latest LTS version:nvm install --lts nvm use --lts
- For Ubuntu/Debian-based systems:
Verify the upgrade worked
Runnode -vagain—you should see a version number like v20.x (or the current LTS release).Reinstall dependencies (optional but safe)
To make sure all your packages (including Ramda) are properly aligned with the new Node version, delete the old dependencies and reinstall:rm -rf node_modules package-lock.json npm installTemporary workaround (if you can't upgrade right now)
If you absolutely have to stick with an old Node version (not recommended!), add the strict mode declaration at the very top of yourapp.js:'use strict'; const R = require('ramda'); // rest of your code...But heads up: Ramda might still use other ES6 features that old Node doesn't support, so this might not fix everything. Upgrading is still the best bet.
Why your previous fixes didn't work
Chances are you were focusing on reinstalling Ramda or tweaking your code, but the root issue was the outdated Node runtime. Modern libraries like Ramda don't support ancient Node versions, so no amount of reinstalling will fix that—you need to get a Node version that understands the syntax Ramda uses.
内容的提问来源于stack exchange,提问作者Нек Траммм

