Windows 7全局安装TypeScript后tsc命令无法识别求助
Hey there, let’s work through this issue step by step—since you’ve already tried reinstalling Node and checking your PATH, we’ll dig into more specific fixes tailored to your setup:
First, confirm your npm global install path
Run this command in your terminal to see where npm is placing global packages:npm config get prefixFrom your install output, it looks like npm is using
C:\Users\[userid].node_modules_globalas the prefix. Now check if there’s abinfolder inside this directory—this is where thetsc.cmdandtsserver.cmdfiles should live (Windows relies on.cmdfiles for executable commands).Add the npm global bin path to your system PATH
If thatbinfolder exists but isn’t in your PATH, Windows won’t locate thetsccommand. Here’s how to fix it:- Right-click "Computer" → select "Properties" → click "Advanced system settings".
- In the "System Properties" window, go to the "Advanced" tab and click "Environment Variables".
- Under "User variables" (stick to this instead of system variables for safety), find the
Pathvariable and click "Edit". - Add the full path to the
binfolder (e.g.,C:\Users\[userid].node_modules_global\bin) to the list, separating it from existing paths with a semicolon (;). - Close and reopen your terminal—PATH changes don’t take effect in already open windows.
Reset npm’s prefix to the default location (if needed)
Custom prefixes can sometimes cause issues if they’re not in your PATH. Let’s reset it to npm’s default Windows path:npm config set prefix "C:\Users\[userid]\AppData\Roaming\npm"Then reinstall TypeScript globally:
npm install -g typescriptThe default
AppData\Roaming\npmfolder is usually added to your PATH automatically during Node installation, so this should resolve the command recognition problem.Verify the fix
After making these changes, runtsc -vin a new terminal. You should see the TypeScript version number (3.4.2, based on your install) if everything works. If not, runwhere tsc—this command will tell you if Windows can locate the executable anywhere on your system.
Let me know if any of these steps resolve your problem, or if you hit any snags along the way!
内容的提问来源于stack exchange,提问作者Quentin Gérard

