A few tips in order
- restart the terminal
- restart the machine
- reinstall nodejs + then run
npm install typescript -g
If it still doesn't work run npm config get prefix to see where npm install -g is putting files (append bin to the output) and make sure that they are in the path (the node js setup does this. Maybe you forgot to tick that option).
A few tips in order
- restart the terminal
- restart the machine
- reinstall nodejs + then run
npm install typescript -g
If it still doesn't work run npm config get prefix to see where npm install -g is putting files (append bin to the output) and make sure that they are in the path (the node js setup does this. Maybe you forgot to tick that option).
You are all messing with the global installations and -path files. Just a little error might damage every project you have ever written, and you will spend the rest of the night trying to get a console.log('hi') to work again.
If you have run npm i typescript --save-dev in your project - just try to run:
npx tsc
And see if it works before messing with global stuff (unless of course you really know what you are doing)
Videos
To be clear, I still want to use my tsconfig.json configuration while I do this.
My reasoning is I started using Vite recently, and I've been blown away by its speed. Obviously one of the downsides of Vite is that it compiles TS code without type checking, so you need to run the type checking after the fact (tsc --noEmit).
My goal is to use TSC for type checking in a similar way to eslint. There is an excellent NPM package, lint-staged, which automatically passes in a comma-separated list of files that have changed to the eslint command. This allows for much more efficient linting of only changing files as a pre-commit hook.
My hope is to find some way to use the CLI options for TSC (or another tool, if one exists) that can perform this same functionality. That way I can enforce all my type-checking as a pre-commit hook and streamline my new Vite workflow.
Thanks so much in advance.
You should not add TypeScript's bin folder directly to the Windows PATH. As you noticed, the files in that bin folder are not directly executable from the command line.
Instead, npm creates a .cmd script for every configured executable in a globally installed package and puts it in:
%APPDATA%\npm
Try updating your PATH to include this folder, re-open your command line and try running tsc again.
Side note: the Node.js installer for Windows by default adds Node and NPM to your Windows path. If you have installed Node.js normally, this should have worked just fine. Anything special about how you have your Node set up?
I'll share a couple of gotchas (that got me!) when I installed typescript (I followed https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html) on windows 10. I had earlier setup node by following the instructions at https://github.com/coreybutler/nvm-windows after failing miserably with other approaches.
Gotcha #1 - Both tsc and tsc.cmd are on the path (at %NVM_SYMLINK%) but tsc is the bash script. In other words you have to use the command tsc.cmd in order to actually invoke the windows version! Just invoking tsc will (in my Powershell terminal) cause it to fall over with weird errors.
Gotcha #2 - Windows file system locking semantics strikes again! Because I had been digging into the problem, I had the tsc.cmd file open in an editor - which was locking the file! This causes the correct invocation (tsc.cmd) to also fail.. till I closed the editor.
Hope this helps someone..