# @homer0/ts-async-import

> Small utility to dynamically import ESM modules in CJS with TS

Latest version **4.0.7** (published 2026-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install @homer0/ts-async-import
pnpm add @homer0/ts-async-import
yarn add @homer0/ts-async-import
bun add @homer0/ts-async-import
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.7 |
| Published | 2026-08-15 |
| First published | 2023-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 0 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 12 |
| Author | Leonardo Apiwan |
| Maintainers | homer0 |
| Keywords | import, commonjs, esm, typescript, require |

## Links

- npm: https://www.npmjs.com/package/@homer0/ts-async-import
- Repository: https://github.com/homer0/packages
- Homepage: https://github.com/homer0/packages#readme
- Issues: https://github.com/homer0/packages/issues
- npm.io page: https://npm.io/package/@homer0/ts-async-import

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 4.0.7 (latest) — 2026-08-15
- 4.0.6 — 2026-08-13
- 4.0.5 — 2026-08-10
- 4.0.4 — 2026-08-09
- 4.0.2 — 2026-08-09
- 4.0.0 — 2026-08-08
- 3.0.9 — 2026-04-26
- 3.0.8 — 2025-12-29
- 3.0.7 — 2025-12-04
- 3.0.6 — 2025-12-03
- 3.0.5 — 2025-12-02
- 3.0.4 — 2025-11-27
- 3.0.3 — 2025-11-24
- 3.0.2 — 2025-11-24
- 3.0.1 — 2025-11-22
- … 16 more at https://npm.io/package/@homer0/ts-async-import/versions

## README

# ☢️ TS Async Import

A wrapper to do dynamic imports in TypeScript contexts that target CommonJS.

## 🍿 Usage

> ⚠️ **Don't use this package if you are targeting ES modules**.

- ⚙️ [Examples](#%EF%B8%8F-examples)
- 🤘 [Development](#-development)

### ⚙️ Examples

```ts
import { tsAsyncImport } from '@homer0/ts-async-import';

// ...

const { default: nodeFetch } =
  await tsAsyncImport<typeof import('node-fetch')>('node-fetch');
```

That's it, the only difference between this and a regular `import` is that you need to specify the type of the module you are importing.

And, if for some reason, you want to specify the context path for the import, you can do it with the second parameter:

```ts
import { tsAsyncImport } from '@homer0/ts-async-import';

// ...

const { default: nodeFetch } = await tsAsyncImport<typeof import('node-fetch')>(
  'node-fetch',
  __dirname,
);
```

### 🤘 Development

As this project is part of the `packages` monorepo, some of the tooling, like `lint-staged` and `husky`, are installed on the root's `package.json`.

#### Tasks

| Task          | Description                     |
| ------------- | ------------------------------- |
| `lint`        | Lints the package.              |
| `test`        | Runs the unit tests.            |
| `types:check` | Validates the TypeScript types. |

## Motivation

I didn't want to have to change my `tsconfig.json` just to prevent TS to transform the two `import`s I have into `require`s 🤬.

---
_Source: https://npm.io/package/@homer0/ts-async-import · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
