canirequire › Dual (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.
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.
| Runtime | require("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).
| Versions | Format | First published |
|---|---|---|
| 10.4.0 – 10.6.0 | Dual (CommonJS + ESM) | Aug 14, 2022 |
| 1.0.0 – 10.3.1 | CommonJS | Apr 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
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
- js-yaml 5.4.1Dual
Similar popularity
- protobufjs 8.8.0CommonJS
- @aws-sdk/credential-provider-node 3.972.82CommonJS
- function.prototype.name 1.2.0CommonJS
- split2 4.2.0CommonJS
- is-array-buffer 3.0.5CommonJS
- string.prototype.trimstart 1.0.8CommonJS
- w3c-xmlserializer 5.0.0CommonJS
- functions-have-names 1.2.3CommonJS