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:
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: [email protected]
(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: [email protected]
(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).
The npx tool can be used to temporarily install TypeScript and run the compiler. Let's break this command down: This command first downloads and installs the typescript npm package. tsc is the executable name of the TypeScript compiler.
Go to: C:\Program Files (x86)\Microsoft SDKs\TypeScript, there you see directories of type 0.9, 1.0 1.1. Enter the high number that you have (in this case 1.1) Copy the directory and run in CMD the command tsc -v, you get the version.
Test that the TypeScript is installed correctly by typing tsc -v into your terminal or command prompt. You should see the TypeScript version print out to the screen. For help on possible arguments you can type tsc -h or just tsc .
TypeScript is available as a package on the npm registry available as "typescript" . You will need a copy of Node. js as an environment to run the package. Then you use a dependency manager like npm, yarn or pnpm to download TypeScript into your project.
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"
"
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With