ArticleZip > Cant Find Typescript Compiler Command Tsc Is Not Valid

Cant Find Typescript Compiler Command Tsc Is Not Valid

Having trouble finding the typescript compiler command and seeing the frustrating "tsc is not valid" error message? Don't worry, you're not alone, and we're here to help you sort out this common issue.

The error message "tsc is not recognized as an internal or external command" typically occurs when the TypeScript compiler command (tsc) is not installed properly or when the system is unable to locate the path to the compiler executable. This issue can be easily resolved by following a few simple steps.

First and foremost, it's essential to ensure that you have TypeScript installed on your system. If you haven't installed TypeScript yet, you can do so using npm, the Node.js package manager, with a simple command:

Plaintext

npm install -g typescript

Once TypeScript is installed, you may still encounter the "tsc is not valid" error if the path to the TypeScript compiler executable is not set correctly. To resolve this, you need to add the TypeScript compiler directory to your system's PATH environment variable.

To add the TypeScript compiler directory to the PATH on Windows:
1. Search for "Environment Variables" in the Windows search bar and select "Edit the system environment variables."
2. In the System Properties window, click on the "Environment Variables" button.
3. Under the "System variables" section, select the "Path" variable and click on the "Edit" button.
4. Click on the "New" button and add the path to the TypeScript compiler directory. The default path is usually something like: `C:UsersYourUserNameAppDataRoamingnpm`.
5. Click "OK" on all windows to save the changes.

To add the TypeScript compiler directory to the PATH on macOS or Linux:
1. Open your terminal and enter the following command to open the .bash_profile (or .zshrc for zsh users):

Plaintext

nano ~/.bash_profile

2. Add the following line to the file, replacing `/usr/local/lib/node_modules/typescript/bin` with the actual path to the TypeScript compiler directory:

Plaintext

export PATH="/usr/local/lib/node_modules/typescript/bin:$PATH"

3. Save and exit the file by pressing `Ctrl + X`, then `Y`, and then `Enter`.
4. Reload the .bash_profile file by running:

Plaintext

source ~/.bash_profile

After adding the TypeScript compiler directory to the PATH, open a new terminal window and try running the `tsc` command again. You should now be able to compile TypeScript files without encountering the "tsc is not valid" error.

By following these simple steps, you can quickly resolve the issue of not finding the TypeScript compiler command and get back to writing and compiling your TypeScript code efficiently.