5

I want to be able to run npx tsc on my project on both my host + guest operating systems. But the guest is using a different (older) version of tsc - and I'm not sure where it's coming from.

My setup:

  • Host OS: Windows 10
  • Guest OS: Debian 9
  • I'm using VirtualBox, and the guest is mounting the host's files using VirtualBox's "shared folders" feature - so it doesn't have a separate copy of the project files - my project is accessed through shared folders at all times.
  • I do NOT have Typescript installed globally (npm -g) on either the host or guest OS (to confirm this, running npm -g ls typescript on both host+guest shows "empty", and running "tsc" alone does not work, as expected).

I have a project with TypeScript 3.3.3333 installed into the project with NPM.

On the Windows host OS, when I cd to the project folder and run:

  • npm ls typescript I see output: typescript@3.3.3333 (as expected)
  • npx tsc --version I see output: Version 3.3.3333 (as expected)

Inside the Linux guest OS, when I cd to the project folder and run:

  • npm ls typescript I see output: typescript@3.3.3333 (as expected)
  • npx tsc --version I see output: message TS6029: Version 1.5.3 (unexpected!)

So I'm unable to run npx tsc to compile my code inside the guest, as it doesn't support some of my newer tsconfig settings.

Where could this tsc 1.5.3 version be coming from, and how do I get rid of it?

Or is there some alternative NPM command I can run on the host that will install a usable tsc into the project that works for both Windows+Linux?

Also, none of the parent folders above my project's root have a node_modules folder (but of course my project's root does have its node_modules sub-folder).

LaVache
  • 2,372
  • 3
  • 24
  • 38

1 Answers1

16

TypeScript binary is called tsc for shortness. When it's not installed globally, npx has no way to know that tsc refers to tsc binary for typescript package. npx tsc refers to deprecated tsc package.

A way this can be fixed is to specify package name explicitly:

npx -p typescript tsc

And the actual problem here is that the project relies on global TypeScript installation. It's common to have typescript a project was written with in project dependencies and refer to local installation in package.json NPM scripts:

...
"scripts": {
  "build": "tsc"
},
"devDependencies": {
  "typescript": "~3.3.0"
"
...
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
  • 4
    Thanks, it appears that `npx -p typescript tsc` does what I need, and correctly reports version 3.3.3333. I'm curious how the old "tsc" package was being run? Because I don't have it installed in the project or globally, and the string "tsc" doesn't even exist anywhere inside my package.json or package-lock.json files. No "tsc" folder under node_modules either. Also `npx tsc --version` was reporting `message TS6029: Version 1.5.3` - which doesn't appear to be a version number for the "tsc" package? (which uses a different format for its version numbers). – LaVache Mar 14 '19 at 06:08
  • 2
    I can't find any "tsc" package anywhere on the host or guest filesystems. Does npx temporarily download a copy and delete it after running or something like that? (I see a message `npx: installed 1 in 1.998s` when I run it) Or otherwise where could the "tsc" package files be coming from? – LaVache Mar 14 '19 at 06:08
  • 1
    Yes, that's what npx does. It installs a temporary copy. That tsc has the latest 1.20150623.0 version and not 1.5.3 means that the package uses different version internally to show with `-v` and doesn't get it from package.json. – Estus Flask Mar 14 '19 at 09:45
  • Sorry but I don't understand why npx don' get new version of TSC? – Murad Sofiyev Oct 19 '20 at 15:05
  • @MuradSofiyev It uses globally installed TS in case there's one. Use `npx --ignore-existing -p typescript tsc` if you want it to behave differently. – Estus Flask Oct 19 '20 at 16:01
  • Yeah but I don't have any globally installed TS this is mean npx must get download lates version of tsc and execute. Am I wrong? But npx download old version of TypeScript :/ – Murad Sofiyev Oct 20 '20 at 01:45
  • @MuradSofiyev What version? Did you check that it's not installed? That you have this problem suggests the opposite. – Estus Flask Oct 20 '20 at 09:18