'npm install -g typescript' doesn't install correctly on windows (missing tsc.cmd)

Viewed 91

Global install of typescript doesn't appear to install correctly on windows.

Steps to reproduce:

  • .Using node v16.16.0 (64bit)

  • .Then 'npm install -g typescript'

  • .I can confirm environment path variables contain: 'C:\Users{MyUserName}\AppData\Roaming\npm' and 'C:\Program Files\nodejs\node_modules'

The node_modules/typescript/bin folder appears a follows: typescript Bin folder image

  • As seen, a tsc file does exist, however the expected tsc.cmd doesn't. This is required for windows to execute.

  • My assumption is this must be system or permissions problem whereby node can't create the tsc.cmd, not necessarily and issue with the
    typescript package

Image for reference: Expected vs now

//----------------

Additional notes:

  • I have also tested this on 10.24.1 using nvm, this is now uninstalled
  • I have ran these steps on another machine, without problems countless times.
  • I have uninstalled (completely) nvm and node before attempting this multiple times.
  • I have performed a complete system search for tsc.cmd I do have wsl installed, perhaps there is some interference there?

Results from suggestions this far: tsc execution image

  • Running locally on a project (Niceman)
2 Answers

I think this is an issue more related to your node path in your environment variables. To test this, install something else globally, like sass for example.

Then you can try sass --version. If it doesn't work the it's probably that your node path is messed up. You can try uninstalling node and reinstall it with the last LTS installing file from the official site. Then you can try to installing typescript again. If that doesn't work you'll need to open the environment variables and check your path for node modules.

Another possible solution is to try using another command line, because maybe a Powershell config is messing up this things. You can try installing git bash. It's not the best, but works.

Solution: use yarn!

As mentioned, I am missing tsc.cmd whatever method I choose (win 11). Who knows what the cause is.

By using yarn :

  • Delete the dudd folder under your node_modules folder from any npm attempts
  • yarn global remove typescript
  • yarn global add typescript
  • add 'C:\Users{yourUserName}\AppData\Local\Yarn\Data\global\node_modules.bin' to your path

As mentiond, you now have the required tsc.cmd: tsc.cmd and version check

What a ride ey!

Related