» npm install tsc
» npm install typescript
Do you use tsc in a production environment? Seems like everyone uses a third-party transpiler.
How to run tsc during npx
npm - 'tsc command not found' in compiling typescript - Stack Overflow
ts-node - how do I know what version of tsc it is actually using?
Is ts-node installed globally along with an older version of Typescript?
More on reddit.comVideos
» npm install ts-node
» npm install vue-tsc
I'm wondering what the use-cases are for tsc as a transpiler, since it seems like almost everyone uses a third-party one. I'd prefer to use tsc instead of relying on an additional dependency, but find it too restrictive. This has me wondering: who does use it?
To be clear: I understand the use-case for tsc as a type-checker, just not as a transpiler.
Edit: I should have specified: this question is about transpiling with tsc for front-end code, not back-end code.
I'm learning typescript and I'm trying to create a script that will execute js files created by tsc. This is my package.json:
{
"bin": "bin/tutorial.js",
"scripts": {
"start": "node bin/tutorial.js",
"prestart": "npm run build",
"build": "tsc"
}bin/tutorial.js is just a custom js file that I wrote that will execute the compiled js files in lib (tsconfig has outDir set to lib):
#!/usr/bin/env node
require('../lib/tutorial');I am able to run the script using npm start, since it will build beforehand. However if I clean the lib directory and do 'npx .' then the tsc build will never happen. This means that the lib directory will be empty and my bin/tutorial.js file won't be able to import the compiled js.
How do I ensure that my scripts executed with npx can run the build step beforehand?
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)