{"id":25210,"library":"embed-typescript","title":"Embed-TypeScript","description":"A library for embedding the TypeScript compiler directly into Node.js or browser applications, providing programmatic compilation, custom transformers, and detailed diagnostics. Current stable version is 3.1.0, with monthly updates. It supports dynamic code compilation without external build tools, includes a CLI for collecting external type definitions from npm packages, and offers a rich diagnostic API. Compared to alternatives like ts-node or esbuild-register, it is designed for in-process compilation with fine-grained control over transformations and error reporting.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/samchon/embed-typescript","tags":["javascript","typescript","compiler","embed","nodejs","browser"],"install":[{"cmd":"npm install embed-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add embed-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add embed-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for compiler functionality; must be installed separately","package":"typescript","optional":false}],"imports":[{"note":"ESM-only; default export is not available. Use named import.","wrong":"const EmbedTypeScript = require('embed-typescript').EmbedTypeScript","symbol":"EmbedTypeScript","correct":"import { EmbedTypeScript } from 'embed-typescript'"},{"note":"TypeScript type; prefer type import to avoid runtime overhead.","wrong":"import { IEmbedTypeScriptResult } from 'embed-typescript'","symbol":"IEmbedTypeScriptResult","correct":"import type { IEmbedTypeScriptResult } from 'embed-typescript'"},{"note":"Module available since v2.0.0; used for embedding ESLint in the same project.","wrong":"","symbol":"EmbedEsLint","correct":"import { EmbedEsLint } from 'embed-typescript'"},{"note":"Type for the fountain function output; added in v1.3.2.","wrong":"","symbol":"IEmbedTypeScriptFountain","correct":"import type { IEmbedTypeScriptFountain } from 'embed-typescript'"}],"quickstart":{"code":"import { EmbedTypeScript } from 'embed-typescript';\nimport ts from 'typescript';\nimport external from './external.json' assert { type: 'json' };\n\nconst compiler = new EmbedTypeScript({\n  external: external as Record<string, string>,\n  compilerOptions: {\n    target: ts.ScriptTarget.ES2015,\n    module: ts.ModuleKind.CommonJS,\n    downlevelIteration: true,\n    esModuleInterop: true,\n    skipLibCheck: true,\n    strict: true,\n  },\n});\n\nconst result = compiler.compile({\n  'example.ts': 'const msg: string = \"Hello, world!\";\\nconst x: number = 42;\\nconsole.log(msg);',\n});\n\nif (result.type === 'success') {\n  console.log('Compiled JavaScript:', result.javascript);\n} else {\n  console.error('Compilation failed:', result.diagnostics);\n}","lang":"typescript","description":"Creates an EmbedTypeScript instance with TypeScript options and external type definitions, compiles a string, and handles success or failure."},"warnings":[{"fix":"Install TypeScript 5.x or 6.x: npm install typescript@^5.0.0","message":"Requires TypeScript >=5.0.0 <7.0.0 as peer dependency","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use npx embed-typescript external --input <dir> --output <file>","message":"CLI command changed from npx embed-typescript collect to npx embed-typescript external","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use npx embed-typescript external to generate external.json from npm packages","message":"External type definitions must be collected manually via CLI; automatic resolution not supported","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set skipLibCheck: true in EmbedTypeScript constructor options","message":"skipLibCheck must be set to true in compilerOptions to avoid lib check errors","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Watch changelog for updates or avoid using fountain function in production","message":"IEmbedTypeScriptFountain type is marked as experimental and may change","severity":"deprecated","affected_versions":">=1.3.2"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run: npm install typescript","cause":"typescript is a peer dependency and not installed automatically","error":"Cannot find module 'typescript'"},{"fix":"Change to: import { EmbedTypeScript } from 'embed-typescript'","cause":"Using default import instead of named import","error":"TypeError: EmbedTypeScript is not a constructor"},{"fix":"Ensure embed-typescript >=3.0.0 and import type correctly: import type { IEmbedTypeScriptResult } from 'embed-typescript'","cause":"Using IEmbedTypeScriptResult incorrectly or with old version","error":"error TS2315: Type 'IEmbedTypeScriptResult' is not generic."},{"fix":"Run: npm install embed-typescript","cause":"Package not installed or incorrect import path","error":"Error: Cannot find module 'embed-typescript'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}