If you've encountered the Typescript errors like "tsc is not recognized" or "cannot be loaded because running scripts is disabled" on Windows Machine, you are at the right place.
Make sure, you have Typescript installed globally using this command.
npm install -g typescript
This command will install TypeScript globally on your machine and should install the tsc
compiler.
To fix "tsc is not recognized as internal or external command", you can add TSC compiler as a windows environment variable.
Fix 1. Add tsc compiler to Windows environment variable:
To locate the tsc compiler location, you can visit this path.
C:\Users\<YourUsername>\AppData\Roaming\npm\node_modules\typescript\bin
This path contains your tsc compiler.
Now, you can add this path to your windows environment variable.
Open Environment Variables:
1. Right-click on This PC or Computer on the desktop or in File Explorer.
2. Select Properties > Advanced system settings.
3. Click on Environment Variables.
Edit the Path Variable:
Under System variables (or User variables), find the Path variable and select Edit.
After adding tsc path to a Windows environment variable, you won't have any error related to tsc is not recognized as internal or external command 😊
Fix 2. Set-ExecutionPolicy RemoteSigned
If you are getting this error cannot be loaded because running scripts is disabled, you can turn this feature on on a Windows machine by running this command in Powershell Make sure to run it as administrator.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Conclusion
By adding tsc as an environment variable in Windows, you streamline your development workflow, allowing you to compile TypeScript files efficiently from any command prompt. This simple setup enhances your productivity by ensuring that the TypeScript compiler is always readily available, making it easier to work on TypeScript projects across different directories without any hassle.