canirequire

canirequireDual (CommonJS + ESM) › decimal.js

Is decimal.js ESM-only? Can you require() it?

An arbitrary-precision Decimal type for JavaScript.

Last verified Sep 9, 2026 against decimal.js@10.6.0. JSON

Dual (CommonJS + ESM) Dual package — both require() and import work

decimal.js publishes both a CommonJS entry and a native ESM entry (ESM added in 10.4.0). require("decimal.js") and import "decimal.js" both work on every supported Node.js version and in Bun.

Latest
10.6.0 (Jul 6, 2025)
Module format
Dual (CommonJS + ESM)
Last CommonJS version
10.6.0
Native ESM since
10.4.0
TypeScript types
Bundled
Node engines
not declared
Weekly downloads
76.6M
License
MIT

Does decimal.js@10.6.0 actually load? Runtime test results

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

Runtimerequire("decimal.js")import "decimal.js"
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 decimal.js

ES modules (import)

import decimalJs from "decimal.js";

CommonJS (require)

const decimalJs = require("decimal.js");

Module format by version

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

VersionsFormatFirst published
10.4.0 – 10.6.0Dual (CommonJS + ESM)Aug 14, 2022
1.0.0 – 10.3.1CommonJSApr 2, 2014

Frequently asked

Is decimal.js ESM-only?

decimal.js@10.6.0 ships CommonJS and ESM builds. decimal.js publishes both a CommonJS entry and a native ESM entry (ESM added in 10.4.0). require("decimal.js") and import "decimal.js" both work on every supported Node.js version and in Bun.

Can I require decimal.js?

Yes. decimal.js ships a CommonJS entry, so require("decimal.js") works on every Node.js version, alongside the native ESM entry for import.

Does decimal.js work in Bun?

Yes. import "decimal.js" loaded successfully in Bun 1.4 on Sep 9, 2026.

Does decimal.js ship TypeScript types?

Yes. decimal.js bundles its own type declarations; no @types package is needed.

Links

Other dual (commonjs + esm) packages

Similar popularity