Registry / devops / ts-import

ts-import

JSON →
library5.0.0-beta.1jsnpmunverified

Dynamically import and compile TypeScript files on the fly in Node.js (>=18). Current stable version is 5.0.0-beta.1, with a release cadence of major and minor updates every few months. It uses native async import (not require), caches compiled JS in node_modules/ts-import/cache, and provides a customizable Compiler class. Key differentiators vs alternatives: it's asynchronous, minimal dependencies (only one internal package with 0 deps), highly configurable with all tsc flags, and does not interfere with native import/require. It has TypeScript type definitions bundled and requires TypeScript 5 as a peer dependency.

npm install ts-import
INSTALL
IMPORT
SIG · TS-IMPORT
T
ts-import
devopsjavascriptv5.0.0-beta.1
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.

tsImport
import { tsImport } from 'ts-import'
import tsImport from 'ts-import'
Named export, not default. This is the standard Compiler instance exported as a named member.
Compiler
import { Compiler } from 'ts-import'
const Compiler = require('ts-import').Compiler
Named export for creating custom compiler instances with different configurations.
Version
import { Version } from 'ts-import'
Exported constant representing the current package version string.

Shows how to use the default tsImport compiler and create a custom Compiler instance with different tsc options.

import { tsImport, Compiler } from 'ts-import'; async function main() { // Use default compiler instance const result = await tsImport.compile('/path/to/file.ts'); console.log(result); // Or create a custom compiler with different options const customCompiler = new Compiler({ compilerOptions: { module: 'esnext', target: 'es2022' } }); const customResult = await customCompiler.compile('/path/to/other.ts'); console.log(customResult); } main().catch(console.error);
Debug
Known issues
breakingts-import v5 is a major rewrite; API changed from v4. The `compile` function is now async and requires Node >=18. Old v4 synchronous API is removed.
fix
Update code to use async/await. Example: const result = await tsImport.compile('file.ts')
affects: >=5.0.0
deprecatedIn v4, the default export was the Compiler class. In v5, use named exports { tsImport, Compiler }.
fix
Change 'import Compiler from 'ts-import'' to 'import { Compiler } from 'ts-import''
affects: >=5.0.0-beta.1
gotchats-import caches compiled files in node_modules/ts-import/cache. If you delete node_modules, the cache is cleared. This can cause slow initial loads after node_modules removal.
fix
Be aware that cache is stored in node_modules. To persist cache, consider using a custom cache directory via Compiler options.
affects: >=1.0.0
gotchaPeer dependency: TypeScript 5 is required. Using ts-import with TypeScript <5 may cause compilation errors or unexpected behavior.
fix
Ensure TypeScript 5 is installed: npm install typescript@5
affects: >=5.0.0
Errors
Common errors & fixes
Error: Cannot find module 'typescript'
Missing peer dependency 'typescript'.
fix
Install typescript: npm install typescript
TypeError: tsImport.compile is not a function
Using incorrect import style (e.g., default import instead of named import).
fix
Use named import: import { tsImport } from 'ts-import'
SyntaxError: Unexpected token 'export'
The compiled output may not match Node's module system (e.g., using ESM but Node expects CommonJS).
fix
Set 'type': 'module' in package.json or use Compiler with module: 'commonjs'.
Error: The module '/path/file.ts' was resolved to a TS file, but --allowImportingTsExtensions was not specified.
TypeScript strict mode requiring explicit extensions.
fix
Pass compilerOptions: { allowImportingTsExtensions: true } to the Compiler.
Upgrade
Version history
5.0.0-beta.1latest on npm
Audit
Dependencies
typescriptrequiredPeer dependency; required to compile TypeScript files. Must be version 5.
Agent activity
9 hits · last 30 days
node
8
Resources
ts-import — npm install ts-import · libregistry