Registry / serialization / embed-typescript

embed-typescript

JSON →
library3.1.0jsnpmunverified

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.

npm install embed-typescript
INSTALL
IMPORT
SIG · EMBED-TYPESCRIPT
E
embed-typescript
serializationjavascriptv3.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

EmbedTypeScript
✓ import { EmbedTypeScript } from 'embed-typescript'
✗ const EmbedTypeScript = require('embed-typescript').EmbedTypeScript
ESM-only; default export is not available. Use named import.
IEmbedTypeScriptResult
✓ import type { IEmbedTypeScriptResult } from 'embed-typescript'
✗ import { IEmbedTypeScriptResult } from 'embed-typescript'
TypeScript type; prefer type import to avoid runtime overhead.
EmbedEsLint
✓ import { EmbedEsLint } from 'embed-typescript'
Module available since v2.0.0; used for embedding ESLint in the same project.
IEmbedTypeScriptFountain
✓ import type { IEmbedTypeScriptFountain } from 'embed-typescript'
Type for the fountain function output; added in v1.3.2.

Creates an EmbedTypeScript instance with TypeScript options and external type definitions, compiles a string, and handles success or failure.

import { EmbedTypeScript } from 'embed-typescript'; import ts from 'typescript'; import external from './external.json' assert { type: 'json' }; const compiler = new EmbedTypeScript({ external: external as Record<string, string>, compilerOptions: { target: ts.ScriptTarget.ES2015, module: ts.ModuleKind.CommonJS, downlevelIteration: true, esModuleInterop: true, skipLibCheck: true, strict: true, }, }); const result = compiler.compile({ 'example.ts': 'const msg: string = "Hello, world!";\nconst x: number = 42;\nconsole.log(msg);', }); if (result.type === 'success') { console.log('Compiled JavaScript:', result.javascript); } else { console.error('Compilation failed:', result.diagnostics); }
embed-typescript --version
Debug
Known issues
breakingRequires TypeScript >=5.0.0 <7.0.0 as peer dependency
fix
Install TypeScript 5.x or 6.x: npm install typescript@^5.0.0
affects: >=3.0.0
gotchaCLI command changed from npx embed-typescript collect to npx embed-typescript external
fix
Use npx embed-typescript external --input <dir> --output <file>
affects: >=2.0.0
gotchaExternal type definitions must be collected manually via CLI; automatic resolution not supported
fix
Use npx embed-typescript external to generate external.json from npm packages
affects: >=1.0.0
gotchaskipLibCheck must be set to true in compilerOptions to avoid lib check errors
fix
Set skipLibCheck: true in EmbedTypeScript constructor options
affects: >=1.0.0
deprecatedIEmbedTypeScriptFountain type is marked as experimental and may change
fix
Watch changelog for updates or avoid using fountain function in production
affects: >=1.3.2
Errors
Common errors & fixes
Cannot find module 'typescript'
typescript is a peer dependency and not installed automatically
fix
Run: npm install typescript
TypeError: EmbedTypeScript is not a constructor
Using default import instead of named import
fix
Change to: import { EmbedTypeScript } from 'embed-typescript'
error TS2315: Type 'IEmbedTypeScriptResult' is not generic.
Using IEmbedTypeScriptResult incorrectly or with old version
fix
Ensure embed-typescript >=3.0.0 and import type correctly: import type { IEmbedTypeScriptResult } from 'embed-typescript'
Error: Cannot find module 'embed-typescript'
Package not installed or incorrect import path
fix
Run: npm install embed-typescript
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies
typescriptrequiredPeer dependency for compiler functionality; must be installed separately
Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
embed-typescript — npm install embed-typescript · libregistry