コンテンツへスキップ
LatchkeyLatchkey home

ts-node vs SWC: CIでTypeScriptをより速く実行する

ts-nodeはtscを通じてTypeScriptを実行します。SWC register(または@swc-node)と組み合わせると、Rust速度のトランスパイルに切り替わり、実行がはるかに速くなります。

ts-nodeはTypeScriptコンパイラ経由でTypeScriptを実行します。SWCのアプローチ(ts-nodeの--swcフラグまたは@swc-node/register)はRustのSWCでトランスパイルし、起動をはるかに高速にしますが、実行中の完全なtype-checkingは行わない代償があります。

ts-nodeSWC (register)
トランスパイルエンジンtscSWC (Rust)
起動速度より遅いはるかに高速
Type checking任意(より遅い)なし(除去のみ)
ESMサポート動作する(設定)動作する
最適な用途型を意識した実行スクリプト/テストの高速実行

CIでは

素のts-nodeは実行しながらtype-checkできますが最も遅い選択肢です。SWC register(またはts-node --swc)を使うと同じworkflowを保ちながらはるかに速くトランスパイルでき、スクリプトとテストの起動を削減します。他の高速トランスパイラと同様、SWCはtype-checkしないため、tsc --noEmitを別途実行します。CIでの純粋な実行速度では、SWCの経路が勝ります。

type-checkを分離する

SWCは型を除去するだけなので、型安全のためにtsc --noEmitステップ(並列)を追加します。どちらもmanaged runnerで動作し、高速なmanaged runnerは大きなコードベースでの長いtype-checkパスを短縮します。

The switching cost is mostly in the parts nobody lists

  • Assertions and mocks usually port mechanically when the target implements a compatible API; custom transformers and framework plugins do not.
  • Snapshot formats differ between runners, so plan to regenerate and review rather than port.
  • Run both suites in parallel in CI for a period and diff the results. A migration that changes which tests fail is not a migration, it is a regression you have not found yet.
  • Coverage numbers move on a runner change even when the tests do not, because instrumentation differs. Re-baseline any coverage gate deliberately.

結論

TypeScriptの実行を最速にしたいなら: ts-nodeをSWC register(または@swc-node)とともに使い、別途のtsc --noEmitチェックを加える。型を意識した実行を1つのツールで必要とするなら: 素のts-node。ほとんどのpipelineは速度とtype-checkingを分けます。

よくある質問

ts-node vs SWC: Running TypeScript Faster in CI?
ts-node executes TypeScript via the TypeScript compiler. The SWC approach (ts-node's --swc flag or @swc-node/register) transpiles with SWC in Rust for far faster startup, at the cost of not running full type-checking during execution.
In CI?
Plain ts-node can type-check as it runs but is the slowest option; using the SWC register (or ts-node --swc) keeps the same workflow while transpiling far faster, which trims script and test startup. As with other fast transpilers, SWC does not type-check, so run tsc --noEmit separately. For sheer execution speed in CI, the SWC path wins.
Type-check separately?
Add a tsc --noEmit step (in parallel) for type safety since SWC only strips types. Both run on CI runners; faster managed runners shorten long type-check passes on large codebases.
Which should I choose?
Want the fastest TypeScript execution: ts-node with the SWC register (or @swc-node), plus a separate tsc --noEmit check. Need type-aware execution in one tool: plain ts-node. Most pipelines split speed from type-checking.

関連ガイド