canirequire

canirequireCommonJS › class-transformer

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

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

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

CommonJS CommonJS — require() works on every Node.js version

class-transformer ships CommonJS only. require("class-transformer") works everywhere. 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.

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

Does class-transformer@0.5.1 actually load? Runtime test results

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

Runtimerequire("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✓ works✓ works

How to import class-transformer

ES modules (import)

import classTransformer from "class-transformer";

Named imports from a CommonJS package only work when Node.js can statically detect them. If a named import fails, use the default import and destructure.

CommonJS (require)

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).

VersionsFormatFirst published
0.1.0 – 0.5.1CommonJSJul 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 everywhere. 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 on Sep 9, 2026.

Does class-transformer ship TypeScript types?

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

Links

Other commonjs packages

Similar popularity