# Is class-transformer ESM-only? Can you require() it?

> class-transformer@0.5.1 is a CommonJS package. CommonJS — require() works on every Node.js version we test.

Proper decorator-based transformation / serialization / deserialization of plain javascript objects to class constructors

Last verified Sep 9, 2026 against class-transformer@0.5.1.

class-transformer ships CommonJS only. require("class-transformer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "class-transformer" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

It also declares a "module" field, so bundlers such as webpack, Vite and esbuild pick up an ESM build for tree-shaking.

## What to do

1. require("class-transformer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun.
2. From ES modules use the default import: import classTransformer from "class-transformer"; then destructure. Named imports only work when Node.js can statically detect the exports.
3. TypeScript: types are bundled; install nothing extra.

## Facts

- Latest: 0.5.1 (Nov 22, 2021)
- Module format: CommonJS
- Last CommonJS version: 0.5.1
- TypeScript types: bundled
- Node engines: not declared
- Weekly downloads: 11.3M
- License: MIT

## Runtime test results for class-transformer@0.5.1

Installed and executed on Sep 9, 2026 with require("class-transformer") from a CommonJS file and import "class-transformer" from an ES module.

| Runtime | require("class-transformer") | import "class-transformer" |
|---|---|---|
| Node.js 18 | works | works |
| Node.js 20 | works | works |
| Node.js 22 | works | works |
| Node.js 24 | works | works |
| Node.js 26 | works | works |
| Bun 1.4.0 | works | works |

## How to import class-transformer

ES modules:

```js
import classTransformer from "class-transformer";
```

CommonJS:

```js
const classTransformer = require("class-transformer");
```

## Module format by version

Derived from the type, main and exports fields of every stable release on npm (21 versions; the newest 21 shown).

| Versions | Format | First published |
|---|---|---|
| 0.1.0 – 0.5.1 | CommonJS | Jul 28, 2016 |

## Frequently asked

**Is class-transformer ESM-only?**

class-transformer@0.5.1 is a CommonJS package. class-transformer ships CommonJS only. require("class-transformer") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "class-transformer" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

**Can I import class-transformer with ES module syntax?**

Yes. import classTransformer from "class-transformer" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

**Does class-transformer work in Bun?**

Yes. import "class-transformer" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

**Does class-transformer ship TypeScript types?**

Yes. class-transformer bundles its own type declarations; no @types package is needed.

## Links

- [class-transformer on npm](https://www.npmjs.com/package/class-transformer)
- [Source repository](https://github.com/typestack/class-transformer)
- [HTML version](https://canirequire.com/package/class-transformer/)
- [JSON version](https://canirequire.com/package/class-transformer.json)

---

For scripts and AI agents: any package is at https://canirequire.com/package/<name>/index.md (Markdown) or https://canirequire.com/package/<name>.json (JSON); the site index is https://canirequire.com/llms.txt. Fetch the URL directly; no search needed.
