Resolving the “tsc Command Not Found” Issue in TypeScript

January, 7th 2025 4 min read

The message “tsc: command not found” appears when the TypeScript compiler is not available in your system’s executable path. This usually happens because TypeScript is not installed globally, because the PATH environment variable does not include the directory where global npm binaries are stored, or because TypeScript is installed only inside a specific project rather than system‑wide.
This guide explains why the error occurs, how to diagnose the underlying cause, and how to fix it on macOS, Linux, and Windows. The explanations focus on real‑world development setups and avoid unnecessary abstractions.


1. Why the Error Appears

Even though the error seems straightforward, it can come from several scenarios:

  • TypeScript is not installed at all.
  • TypeScript is installed but only locally in a single project.
  • TypeScript is installed globally, but the system cannot find the executable because PATH is misconfigured.
  • Node.js or npm is installed incorrectly or using a nonstandard directory.
  • You are using version managers such as nvm, fnm, volta, or asdf and the environment is not fully initialized.

Understanding the exact cause helps avoid installing packages repeatedly without solving the underlying issue.


2. Check Whether TypeScript Is Installed

Start by checking if the compiler exists on your system:

bash
tsc --version

If the terminal returns the version number, TypeScript is globally available.
If the terminal responds with “command not found,” the system cannot locate the binary.

You can also check whether TypeScript exists locally inside a project:

bash
npm list typescript

If this returns a version, then TypeScript is installed but only within that project.


3. Installing TypeScript Globally

If you want tsc to be available in every folder on your machine, install it globally:

bash
npm install -g typescript

After installation, verify:

bash
tsc --version

If the command still fails, the package may be installed correctly but the executable directory is not added to PATH.


4. Understanding the PATH Issue

npm installs global binaries in a specific folder. The operating system must know where that folder is. If the directory is not included in PATH, no command inside it can be executed by name.

Where npm stores global binaries

You can check the exact path with:

bash
npm config get prefix

Inside this prefix, the executable binaries are located in:

plaintext
<prefix>/bin

If this directory is not part of PATH, the system does not know where tsc is.


5. Fixing PATH on macOS and Linux

To add the npm global binary directory to PATH, append the following line to your shell configuration file (~/.zshrc, ~/.bashrc, or ~/.profile):

bash
export PATH="$PATH:$(npm config get prefix)/bin"

After saving the file, reload your terminal:

bash
source ~/.zshrc

(or the configuration file you edited).

Now test:

bash
tsc --version

If the version appears, PATH is configured correctly.


6. Fixing PATH on Windows

On Windows, npm global binaries are commonly stored in:

plaintext
C:\Users\<YourUser>\AppData\Roaming\npm

To add this directory to PATH:

  1. Open System PropertiesAdvancedEnvironment Variables.
  2. Find Path under your user variables.
  3. Add the npm directory path from above.
  4. Restart your terminal.

After making the change, run:

powershell
tsc --version

If TypeScript loads, the PATH was the underlying issue.


7. Running tsc with npx (When TypeScript Is Local)

If a project uses TypeScript locally and you do not want a global installation, the correct way to access the compiler is:

bash
npx tsc --version

npx automatically resolves the local version installed in the project’s node_modules folder.
This is the preferred approach in large multi-project repositories, monorepos, or CI environments.


8. Using Version Managers (nvm, fnm, volta, asdf)

Node version managers often cause confusion because each Node version has its own global package directory. If you switch Node versions without reinstalling global tools, the system may lose access to previous global installations.

For example, after switching Node versions with nvm:

bash
nvm use 20
tsc --version # may fail

You may need to reinstall TypeScript globally for the specific version managed by nvm:

bash
npm install -g typescript

Alternatively, avoid global installations entirely and use npx in each project.


9. Checking Node.js and npm Installation

Since tsc is installed through npm, incorrect or partial installation of Node.js can cause the error.

Verify the installations:

bash
node -v
npm -v

If either command fails, reinstall Node.js from:

https://nodejs.org

Or, if using a version manager, reinstall Node within your environment.


10. Reinstall TypeScript When Necessary

If the installation is corrupted or incomplete, reinstalling can help:

bash
npm uninstall -g typescript
npm install -g typescript

Always verify after reinstalling:

bash
tsc --version

11. Global vs Local Installations: When Each Makes Sense

Global installation is useful when:

  • You compile small scripts outside any project.
  • You prefer running tsc without npx.
  • You need global CLIs available everywhere.

Local installation is better when:

  • You work in teams and want consistent TypeScript versions.
  • You maintain multiple projects with different configurations.
  • You use CI environments that avoid global tools.

In modern setups, many developers rely primarily on local installations and npx, using global TypeScript only for experimentation or sysadmin scripts.


Conclusion

The “tsc: command not found” error is straightforward once you understand how npm installs global binaries and how PATH determines whether your system can locate them.
By verifying the installation, checking PATH configuration, and understanding the difference between global and local TypeScript setups, you can ensure that your development environment remains consistent and reliable.

Correct installation and configuration allow TypeScript to run smoothly and prevent this error from interrupting your workflow.