{"id":10422,"library":"ts-node","title":"TypeScript Node.js Runtime","description":"ts-node provides a TypeScript execution environment and REPL for Node.js, offering direct execution of TypeScript files without precompilation, full source map support, and native ESM capabilities. The current stable version is 10.9.2. Releases are frequent, typically addressing bug fixes, performance improvements, and adding support for new TypeScript and Node.js features.","status":"active","version":"10.9.2","language":"javascript","source_language":"en","source_url":"git://github.com/TypeStrong/ts-node","tags":["javascript","typescript","node","runtime","environment","ts","compiler"],"install":[{"cmd":"npm install ts-node","lang":"bash","label":"npm"},{"cmd":"yarn add ts-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-node","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"symbol":"register","correct":"import { register } from 'ts-node'"}],"quickstart":{"code":"/* file.ts */\nfunction greet(name: string): string {\n  return `Hello, ${name}!`\n}\n\nconsole.log(greet('ts-node user'))\n\n// To run this: ts-node file.ts","lang":"typescript","description":"Demonstrates how to create a simple TypeScript file and execute it directly using the `ts-node` command-line interface."},"warnings":[{"fix":"Use `ts-node --esm <file.ts>`, the `ts-node-esm` binary, or configure `\"ts-node\": {\"esm\": true}` in your `tsconfig.json` for native ESM projects.","message":"Prior to `ts-node` v10.7.0, native ECMAScript module (ESM) support often relied on using `NODE_OPTIONS='--loader ts-node/esm'`. The `--esm` flag (or `ts-node-esm` binary) introduced in v10.7.0+ provides a more robust and direct way to enable ESM, deprecating the `--loader` approach for most use cases.","severity":"deprecated","affected_versions":">=10.7.0"},{"fix":"Upgrade `ts-node` to v10.9.1 or higher, which includes a workaround for the Node.js bug.","message":"Users running `ts-node` with the `--esm` flag on Node.js versions >=18.6.0 may encounter a Node.js bug causing issues with module resolution or loading.","severity":"gotcha","affected_versions":"<10.9.1"},{"fix":"Upgrade `ts-node` to v10.9.2 or higher to resolve the `tsconfig.json` file-not-found issue.","message":"A regression in some recent TypeScript versions could cause `tsconfig.json` files to not be found by `ts-node` when invoked in certain ways, leading to unexpected compilation behavior.","severity":"gotcha","affected_versions":"<10.9.2"},{"fix":"Add `\"ts-node\": { \"experimentalResolver\": true }` to your `tsconfig.json` or use the `--experimental-resolver` CLI flag.","message":"When using `module=NodeNext` or `module=Node16` in your `tsconfig.json`, `ts-node` recommends enabling the `experimentalResolver` option for best results with module resolution.","severity":"gotcha","affected_versions":">=10.8.0"},{"fix":"Ensure your `@swc/core` or `@swc/wasm` package meets `ts-node`'s peer dependency of `>=1.2.50` and supports the `target` specified in your `tsconfig.json`. Upgrade `@swc/core` if necessary.","message":"If using `@swc/core` or `@swc/wasm` as the `transpiler`, an older version might not support the `target` specified in your `tsconfig.json`, resulting in a runtime error.","severity":"gotcha","affected_versions":"all versions"}],"env_vars":null,"last_verified":"2026-04-18T00:00:00.000Z","next_check":"2026-07-17T00:00:00.000Z","problems":[{"fix":"Review the subsequent error messages from TypeScript for specific details. Ensure your `tsconfig.json` is correctly configured and your code passes TypeScript's type checks.","cause":"TypeScript failed to compile your code, often due to type errors, syntax issues, or an incorrect `tsconfig.json` configuration.","error":"TSError: ⨯ Unable to compile TypeScript"},{"fix":"For native ESM, ensure you are using `ts-node --esm`, the `ts-node-esm` binary, or `\"ts-node\": {\"esm\": true}` in your `tsconfig.json`. For CommonJS, use `require()`/`module.exports` or adjust your `tsconfig.json`'s `module` option to `CommonJS`.","cause":"Attempting to use ES Modules syntax (like `import`/`export`) in a CommonJS context without proper configuration, or if `ts-node` isn't correctly configured for ESM.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Convert your code to use dynamic `import()` or enable `ts-node`'s native ESM support (e.g., `ts-node --esm`). Additionally, ensure your project's `package.json` has `\"type\": \"module\"` if you intend to use native ESM.","cause":"Attempting to `require()` an ES Module file from a CommonJS context or when `ts-node` isn't fully configured for ESM.","error":"ERR_REQUIRE_ESM: Must use import to load ES Module"},{"fix":"Ensure `ts-node` is correctly invoked (e.g., `ts-node script.ts`, `#!/usr/bin/env ts-node`, or `ts-node --esm`). For extensionless entrypoints with Node's `--loader`, `ts-node` v10.6.0+ includes workarounds, so ensure you are on a recent version.","cause":"Node.js does not recognize the `.ts` extension without a loader or full `ts-node` ESM integration. This can also occur with extensionless entrypoints when using Node's `--loader` flag.","error":"ERR_UNKNOWN_FILE_EXTENSION: Unknown file extension .ts"},{"fix":"Upgrade your `@swc/core` (or `@swc/wasm`) package to a version that meets `ts-node`'s peer dependency of `>=1.2.50` and supports the `target` specified in your `tsconfig.json`.","cause":"The installed `@swc/core` or `@swc/wasm` version does not support the JavaScript `target` (e.g., `ES2022`) specified in your `tsconfig.json`.","error":"Error: @swc/core version is too old to support your tsconfig.json target"}],"ecosystem":"npm"}