You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
No, not really. In production you'd want to only be in transpile mode (you should have already type checked). If someone wants to contribute some PRs for this functionality, we can get it in. Otherwise I'd wait for #44.
Reacted by Aayush Kapoor, Ondrej Slinták, Kristijan Sedlak, Tino, Ivan Wang, mpachin, Adrian Li, David Jensen, leonardojimenez, Cheddah and 3 more
So @blakeembrey, can we now use it in production? As in
$ ts-node -F server.ts
I currently do tsc && node build/server.js, but the very succinctness and beauty of the above is totally worth it if I'll get no significant overheads over the second option.
Reacted by Jose, Cody Swartz, Davide Crestini, Ivan Wang, Mark Elphinstone, Adrian Li, Hiroaki Date, Arad Alvand, Riku Rainio and Oliver Clennan
Reacted by Artem Sapegin, jackwilsdon, Евгений Остапенко, Cody Swartz, Ivan Wang, Mark Elphinstone, Alex Chambers, Zane Helton, Amit Rajput, Riku Rainio and 1 more
Definitely your choice, go ahead 😄 There's no heavy overheads.
Reacted by webgenapp, Amir Muhammad Hakim, Craig Luedtke, a, Maikel Ruiz, Pickaxe828, Oliver Clennan and Muhammed Rahif
Reacted by Prashant Tiwari, Romain Lanz, Vladimir Buskin, Jordan Schroter, Iago Alves, Cody Lundquist, Gurdas Nijor, Kristijan Sedlak, Chase Brewer, Gen and 59 more
That make sense to me. Fast mode isn’t using type information, it’s just plain transpiling files on the fly. That’s not equivalent to tsc. Use the regular mode that is if you want type information. It’s a good point though and I can document that.
That's not something I can tell you. I can tell you that loading type information has a larger overhead, but it shouldn't impact performance (only memory once started).
Reacted by Nathan Phillip Brink, John ⚒ Waw3ru, Pedro Martin, Ivan Wang, mpachin, Gabo Esquivel, motiejunas, akhader-mc, Thays dos Santos and Elvira B
Hey, FYI there still no documentation mention about the --fast or -F option. I just found it here. That's something worth adding to the readme along with a basic intro about what it does, if its still a valid option. I saw somewhere that it's enabled by default, is that true?
Reacted by LeoTM, Benny Neugebauer and Arad Alvand
Go ahead and use ts-node in production; just set the --transpile-only flag.
Is that correct?
Reacted by Frank Orellana, Kaelan Cooter, Andrew Schmadel, Benny Neugebauer, Ro, OKIMATSU Ryusuke, Arad Alvand, alsotang, Ayaan Zaidi and Shubh A Chudasama
In this mode, files are only transpiled without typechecking, greatly improving compilation speed. All this means is your console won't spit out TypeError warnings, but if you use VSCode you already get realtime warnings within the editor.
Reacted by Ionel lupu, Ian Bytchek, Danny Hurlburt, Fran Plaza, Timo Friedl, Catherine Davie, 0z00, Yuichi, Vinaya Bhattarai, Aman Mehta and 4 more
@iiian I don't think there is one, as long as you pass the correct flag disabling type checking. The one mentioned above may be outdated and I recommend you to check manual for the exact name.
Reacted by Kamil Chmielewski, Wyatt Arent, Julien Heller, Andres Serrano, Boy van der Laak, LF, Ajdien Taravati, Juan Carlos Arocha, Tejovanth N, Justin Nguyen and 94 more
Reacted by Ian Bytchek, Niklas Molnes Hole and Oleksandr Oles Stovbenko
Reacted by Wyatt Arent, Thawan Keane, Joe Barnett, Hai Truong, cameronspeakflash, Benjamin DANIEL, Niklas Molnes Hole, Duc Nguyen, Snorre Lothar von Gohren Edwin, Marcos Silva and 29 more
Thumbs up and sad face because going to production and afraid
Reacted by Julien Heller, Rick Bowen, Tejovanth N, Justin Nguyen, Joe Barnett, Denis F., zahgboat, Peter Boyer, Grégoire THIEBAULT, Ryohei Hisamitsu (hissan) and 27 more
Thumbs up and sad face because going to production and afraid
Same! Been migrating a node.js app to typescript. I tried running "tsc && node dist/app.js" but kept getting cannot find module from a local ts file. This is the only resort unfortunately, fingers crossed.
@bluematter you'll probably have better luck in the TypeScript Community Discord: https://discord.com/invite/typescript
It's very active, with plenty of people answering questions. Be prepared to ask your question with sufficient detail, and you should get a good answer.
It's an old topic but I want to share a code I wrote for testing purposes and its results. I wrote a simple function that calculates Fibonacci numbers for the code that uses both CPU and memory, and I print out the time required for the calculation and how much RAM it uses in that time, you can try it yourself. I am attaching the results below.
It seems that there is not much difference in speed but there is a difference in memory usage and "--transpile-only" doesn't change much about it
let operations = 0;
// Fibonacci calculation function
function fibonacci(num: number): number {
operations++;
if (num <= 1) return 1;
return fibonacci(num - 1) + fibonacci(num - 2);
}
// Start the time
const start = Date.now();
// You can set the parameter value depending on your hardware capacity.
// Be careful, this number exponentially increases the number of operations required
const fibNum = fibonacci(45);
// Calculate elapsed time
const elapsedSeconds = (Date.now() - start) / 1000;
const used = process.memoryUsage().heapUsed / 1024 / 1024;
console.log(`Time elapsed: ${elapsedSeconds} seconds`);
console.log(`Memory used: ${Math.round(used * 100) / 100} MB`);
Reacted by 0xdeadc0d3, Gabriel Zimmermann, Viktor Tsvetkov, Leonardo Muñoz, Slav Ivanov, Luís Figueiredo, Tim Nikolsky, Justin Dodge, Jaakko Niemensivu, Mero and 16 more
Reacted by Álvaro Patrício, Thays dos Santos and AbdulRehman Muhammad Younis
It seems that there is not much difference in speed but there is a difference in memory usage and "--transpile-only" doesn't change much about it
We actually just faced an outage because of this as the max size of the heap in Node.js by default is 512mb. We were getting very close to it before, but we moved some packages around in our monorepo and that made ts-node hit that limit. Thankfully we didn't have --transpile-only set, so setting it did alleviate the issue slightly, but the amount of memory being used is still absurdly close to the limit.
Obviously we can increase the limit using --max-old-space-size, but another more demanding service is running with less memory (it's only using node) so we do want to make sure ts-node is our only option before we increase the size of the memory footprint.
@leventkaragol thanks for sharing your benchmark and results.
I've pasted your code into src/index.ts and ran it on my machine (m1 mac) with both node 18 (v18.17.1) and node 20 (v20.10.0) and I noticed some differences in the results:
node 18
node dist/index.js => 4.92 MB and 16.321 seconds
npx ts-node src/index.ts => 102.26 MB and 15.538 seconds
npx ts-node --transpile-only src/index.ts => 31.21 MB and 15.547 seconds
node 20
node dist/index.js => 3.37 MB and 16.284 seconds
npx ts-node src/index.ts => 109.67 MB and 15.646 seconds
npx ts-node --transpile-only src/index.ts => 23.77 MB and 15.529 seconds
Tests report the memory footprint is reduced significantly when using --transpile-only both on node 18 and node 20.
However, the most interesting result that tests report comes from Node20, when switching from CommonJS to ESM (by adding "type": "module" in package.json).
You'll have to ditch the ts-node executable and replace it with node --loader ts-node/esm because of this #1997 , and cope with a warning that's there since node14 (but I think there's a newer flag or api to get rid of that)
node 20 ESM
node dist/index.js => 3.92 MB and 16.569 seconds
node --loader ts-node/esm src/index.ts => 3.63 MB and 16.46 seconds
node --loader ts-node/esm/transpile-only src/index.ts => 3.62 MB and 16.599 seconds
So, for this last test, it looks like the memory usage is not affected at all by the ts-node/esm loader.
Hope this can be helpful to people researching on the same topic.
Reacted by Benny Neugebauer, Chi-Heng Huang, Mat Silva, NEM, Diluka, Parsa Shamaeezadeh, Markus Peitl, CodinCat, Aidar, Dilyan G. and 16 more
Activity
blakeembrey commentedon Apr 27, 2016
No, not really. In production you'd want to only be in transpile mode (you should have already type checked). If someone wants to contribute some PRs for this functionality, we can get it in. Otherwise I'd wait for #44.
prashaantt commentedon Sep 28, 2016
So @blakeembrey, can we now use it in production? As in
I currently do
tsc && node build/server.js, but the very succinctness and beauty of the above is totally worth it if I'll get no significant overheads over the second option.blakeembrey commentedon Sep 28, 2016
Definitely your choice, go ahead 😄 There's no heavy overheads.
Diluka commentedon Oct 16, 2017
using
ts-node -F .to run ts code missing metadata.reflect-metadatacan't get field's type.tsc && node .is OKblakeembrey commentedon Oct 16, 2017
That make sense to me. Fast mode isn’t using type information, it’s just plain transpiling files on the fly. That’s not equivalent to
tsc. Use the regular mode that is if you want type information. It’s a good point though and I can document that.Diluka commentedon Oct 17, 2017
So, should I use in production?
ts-node .ortsc && node .blakeembrey commentedon Oct 17, 2017
That's not something I can tell you. I can tell you that loading type information has a larger overhead, but it shouldn't impact performance (only memory once started).
IAMtheIAM commentedon Dec 26, 2017
Hey, FYI there still no documentation mention about the
--fastor-Foption. I just found it here. That's something worth adding to the readme along with a basic intro about what it does, if its still a valid option. I saw somewhere that it's enabled by default, is that true?blakeembrey commentedon Dec 31, 2017
It's the default behaviour. See https://github.com/TypeStrong/ts-node/releases/tag/v4.0.0.
leotm commentedon Sep 20, 2018
The release note mentions use --type-check for type checking behaviour, but its not mentioned again in the docs?
blakeembrey commentedon Sep 20, 2018
That’s because it was three major releases ago and the behaviour was reverted. It confused other people to not type check by default.
FranklinYu commentedon Oct 27, 2018
So the
--transpileOnlyworks similar to previous--fast?blakeembrey commentedon Oct 27, 2018
The same, yes.
6 remaining items
lukewlms commentedon Aug 23, 2019
So the new summary of this thread is:
Go ahead and use ts-node in production; just set the
--transpile-onlyflag.Is that correct?
saoudrizwan commentedon Aug 27, 2019
For anyone wondering how to pass in
--transpile-onlywhen requiring ts-node in a node call:A little bit about
transpileModulefor the curious: https://github.com/microsoft/TypeScript/blob/master/src/services/transpile.ts#L17In this mode, files are only transpiled without typechecking, greatly improving compilation speed. All this means is your console won't spit out TypeError warnings, but if you use VSCode you already get realtime warnings within the editor.
flux627 commentedon Sep 6, 2019
A user early in this thread said that
reflect-metadatabroke when using this in-T(at the time it was-F) mode. Is this still the case?EDIT: It looks like this is still a problem according to #873
blakeembrey commentedon Sep 6, 2019
Yes, it’s not possible to get type information if your compiling without type information - which is what transpile only does.
schmod commentedon Sep 11, 2019
I haven't seen any issues with sequelize-typescript – the current limitation may be specifically limited to the enum issue described in #873.
iiian commentedon Dec 2, 2019
General query to this thread: Out of curiosity, what are the arguments for not using
ts-nodein production ? Is there a good, important reason?FranklinYu commentedon Dec 2, 2019
@iiian I don't think there is one, as long as you pass the correct flag disabling type checking. The one mentioned above may be outdated and I recommend you to check manual for the exact name.
rrrix commentedon Jul 23, 2020
Thumbs up if you're using
ts-nodein Production 😁I am! 👍
Sad face if you're too afraid 😢
warent commentedon Jul 24, 2020
Thumbs up and sad face because going to production and afraid
justinTime225 commentedon Aug 8, 2020
Same! Been migrating a node.js app to typescript. I tried running "tsc && node dist/app.js" but kept getting
cannot find modulefrom a local ts file. This is the only resort unfortunately, fingers crossed.bluematter commentedon Aug 22, 2020
I deployed the other day and broke things :/ I build a video editor https://storycreatorapp.com and recently migrated my node server to TypeScript.
The reason it broke is that I was trying to get it to work with pm2.
Are you guys running your node.js servers in production without https://pm2.keymetrics.io/? That seems scary to me.
Has anyone gotten it to work with pm2?
cspotcode commentedon Aug 24, 2020
@bluematter you'll probably have better luck in the TypeScript Community Discord: https://discord.com/invite/typescript
It's very active, with plenty of people answering questions. Be prepared to ask your question with sufficient detail, and you should get a good answer.
leventkaragol commentedon Jun 7, 2023
It's an old topic but I want to share a code I wrote for testing purposes and its results. I wrote a simple function that calculates Fibonacci numbers for the code that uses both CPU and memory, and I print out the time required for the calculation and how much RAM it uses in that time, you can try it yourself. I am attaching the results below.
It seems that there is not much difference in speed but there is a difference in memory usage and "--transpile-only" doesn't change much about it
divmgl commentedon Sep 1, 2023
We actually just faced an outage because of this as the max size of the heap in Node.js by default is 512mb. We were getting very close to it before, but we moved some packages around in our monorepo and that made
ts-nodehit that limit. Thankfully we didn't have--transpile-onlyset, so setting it did alleviate the issue slightly, but the amount of memory being used is still absurdly close to the limit.Obviously we can increase the limit using
--max-old-space-size, but another more demanding service is running with less memory (it's only usingnode) so we do want to make surets-nodeis our only option before we increase the size of the memory footprint.cybercase commentedon Feb 13, 2024
@leventkaragol thanks for sharing your benchmark and results.
I've pasted your code into
src/index.tsand ran it on my machine (m1 mac) with both node 18 (v18.17.1) and node 20 (v20.10.0) and I noticed some differences in the results:node 18
node dist/index.js=> 4.92 MB and 16.321 secondsnpx ts-node src/index.ts=> 102.26 MB and 15.538 secondsnpx ts-node --transpile-only src/index.ts=> 31.21 MB and 15.547 secondsnode 20
node dist/index.js=> 3.37 MB and 16.284 secondsnpx ts-node src/index.ts=> 109.67 MB and 15.646 secondsnpx ts-node --transpile-only src/index.ts=> 23.77 MB and 15.529 secondsTests report the memory footprint is reduced significantly when using
--transpile-onlyboth on node 18 and node 20.However, the most interesting result that tests report comes from Node20, when switching from CommonJS to ESM (by adding "type": "module" in
package.json).You'll have to ditch the
ts-nodeexecutable and replace it withnode --loader ts-node/esmbecause of this #1997 , and cope with a warning that's there since node14 (but I think there's a newer flag or api to get rid of that)node 20 ESM
node dist/index.js=> 3.92 MB and 16.569 secondsnode --loader ts-node/esm src/index.ts=> 3.63 MB and 16.46 secondsnode --loader ts-node/esm/transpile-only src/index.ts=> 3.62 MB and 16.599 secondsSo, for this last test, it looks like the memory usage is not affected at all by the
ts-node/esmloader.Hope this can be helpful to people researching on the same topic.