You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux环境下Node.js运行app.js报const严格模式语法错误求助

解决Node.js启动时的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 -v
    

    If 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:
      1. Remove the old Node.js and npm first:
        sudo apt remove nodejs npm -y
        
      2. Add the official NodeSource LTS repository:
        curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
        
      3. Install the latest LTS Node.js:
        sudo apt install nodejs -y
        
    • For CentOS/RHEL-based systems:
      1. Uninstall old versions:
        sudo yum remove nodejs npm -y
        
      2. Add the NodeSource LTS repo:
        curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
        
      3. Install Node.js:
        sudo yum install nodejs -y
        
    • 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
      
  • Verify the upgrade worked
    Run node -v again—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 install
    
  • Temporary 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 your app.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,提问作者Нек Траммм

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:08:19