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

为何Node.js包与CLI命令无法被识别?

Fix for "ng/nodemon is not recognized as a cmdlet/function" Error

Hey there! It sounds like your terminal can't locate the executable files for global Node.js packages like ng (Angular CLI) and nodemon. This almost always boils down to a system PATH environment variable issue—the folder where these global tools are stored isn't listed in your PATH, so your shell doesn't know where to look for them. Let's walk through how to fix this step by step:

Step 1: Find your Node.js global package directory

First, let's confirm where npm installs global tools. Open your terminal and run this command:

npm root -g

This will output the root folder for global Node modules. The corresponding executable files (the actual ng/nodemon commands) are stored in a related folder:

  • Windows: Typically C:\Users\<YourUsername>\AppData\Roaming\npm (just remove the node_modules suffix from the npm root -g output)
  • Mac/Linux: Usually /usr/local/bin or ~/.npm-global/bin (check if this path exists alongside your global modules folder)

Step 2: Check if the path is in your system PATH

Next, verify if this executable folder is included in your system's PATH variable:

  • Windows:
    1. Right-click "This PC" → "Properties" → "Advanced System Settings" → "Environment Variables"
    2. Look for the PATH variable under either "User Variables" (your account only) or "System Variables" (all users)
    3. Check if the npm executable path from Step 1 is listed here
  • Mac/Linux:
    Run this command in your terminal:
    echo $PATH
    
    Look for your npm executable folder in the colon-separated list of paths.

Step 3: Add the path to PATH (if missing)

If the path isn't in your PATH variable, add it:

  • Windows:
    1. Select the PATH variable and click "Edit"
    2. Click "New" and paste the npm executable path
    3. Click "OK" to save all changes, then restart all open terminal windows (critical—old terminals won't pick up the new PATH)
  • Mac/Linux:
    1. Open your shell configuration file (e.g., ~/.bash_profile for Bash, ~/.zshrc for Zsh) in a text editor
    2. Add this line at the end (replace /path/to/npm/bin with your actual path):
      export PATH="$PATH:/path/to/npm/bin"
      
    3. Save the file and run this command to apply changes immediately:
      source ~/.bash_profile # or source ~/.zshrc
      

Step 4: Verify the fix

Restart your terminal (if you haven't already) and test the commands:

ng --version
nodemon --version

If you see version numbers printed, the issue is resolved!

Extra Troubleshooting Tips

  • Check Node.js installation: Run node -v and npm -v to confirm Node and npm are installed correctly. If these commands also fail, reinstall Node.js—make sure to check the "Add to PATH" option during installation (it's selected by default, but double-check!).
  • If using nvm: If you manage Node versions with nvm, ensure nvm's path is in your PATH, and you've activated the correct Node version with nvm use <your-version>. Run nvm list to see your installed versions and current active one.

That should cover the most common fixes for this issue. Let me know if you hit any roadblocks!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 10:32:30