ts-eager

raw JSON →
2.0.2 verified Fri May 01 auth: no javascript

ts-eager is a fast TypeScript runner and register hook that uses esbuild for eager compilation of all included files from tsconfig.json at startup, with fallback to lazy compilation for files outside the project. Version 2.0.2 is the latest stable release, updated to support esbuild v0.11.20 with compatibility for newer versions. It differentiates from ts-node by leveraging esbuild's speed for noticeable improvements in tasks like test runs, and offers fallback to ts-node for type-specific features like emitDecoratorMetadata and optional tsconfig-paths support for path mapping.

error Error: dynamic require of 'esbuild' is not supported
cause Using ts-eager in an ES module context where dynamic require is not allowed.
fix
Run node with --require ts-eager/register (CommonJS mode) or convert your project to CommonJS.
error Error: Cannot find module 'typescript'
cause Typescript is not installed, but required to parse tsconfig.json.
fix
Install typescript: npm install -D typescript
error Error: esbuild: Failed to resolve 'esbuild'
cause esbuild peer dependency not installed.
fix
Install esbuild: npm install -D esbuild
breaking Major version bump to v2.0.0 due to breaking changes in esbuild >=0.11.20. Older esbuild versions are incompatible.
fix Update to ts-eager@2 and esbuild@^0.11.20.
gotcha Default ESBUILD_MAX_BUFFER is 16MB which may be too small for medium projects; ts-eager v2.0.1+ sets 256MB if not already set.
fix Set environment variable ESBUILD_MAX_BUFFER=268435456 or upgrade to v2.0.1+.
gotcha ts-eager only transpiles, does not type-check. Use tsc separately for type checking.
fix Run tsc --noEmit in parallel or as a pre-build step.
deprecated Support for emitDecoratorMetadata requires ts-node to be installed as a fallback.
fix Install ts-node: npm install -D ts-node
npm install ts-eager
yarn add ts-eager
pnpm add ts-eager

Shows how to use ts-eager as a require hook to run a TypeScript file with eager compilation.

// Install dependencies
// npm install -D ts-eager typescript esbuild

// Create a TypeScript file: hello.ts
export function greet(name: string): string {
  return `Hello, ${name}!`;
}

// Run with ts-eager
// Command: node -r ts-eager/register -e "const { greet } = require('./hello'); console.log(greet('World'));"