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

npm安装报错求助:SyntaxError: Unexpected token ILLEGAL问题解决

分析与解决方案

Hey, let's work through this issue together—here's exactly what's going wrong and how to fix it:

问题根源

You mentioned installing Node.js 9.4.0, but when you ran node -v, it returned v0.12.7. That's the core problem: your system is still using this extremely outdated Node version (v0.12.7 is from 2014!).

Newer versions of npm rely on ES6 features like template literals (the `-wrapped strings in your error message), which v0.12.7 doesn't support at all. That's why you're getting the SyntaxError: Unexpected token ILLEGAL error when trying to run npm commands.

解决步骤

Follow these steps to get the correct Node version working and fix the npm issue:

  1. Uninstall the old Node.js and clean up residues
    If you originally installed the old Node via Homebrew, run:

    brew uninstall node
    

    Then manually remove any leftover files to avoid conflicts:

    rm -rf /usr/local/lib/node_modules
    rm /usr/local/bin/node
    rm /usr/local/bin/npm
    
  2. Reinstall Node.js 9.4.0
    Use Homebrew to install the specific version you need:

    brew install node@9.4.0
    

    Next, add this version to your system PATH so your terminal uses it by default:

    # For Zsh users
    echo 'export PATH="/usr/local/opt/node@9/bin:$PATH"' >> ~/.zshrc
    # For Bash users, use ~/.bash_profile or ~/.bashrc instead
    echo 'export PATH="/usr/local/opt/node@9/bin:$PATH"' >> ~/.bash_profile
    

    Refresh your shell configuration to apply the change:

    # Zsh
    source ~/.zshrc
    # Bash
    source ~/.bash_profile
    
  3. Verify the installation
    Run these commands to confirm you're now using the correct Node and npm versions:

    node -v # Should output v9.4.0
    npm -v # Should show an npm version compatible with Node 9.4.0
    
  4. Install grunt-cli again
    Now that your environment is fixed, run the install command again—it should work without errors:

    npm install -g grunt-cli
    

内容的提问来源于stack exchange,提问作者Han Zhengzu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 07:54:21