canirequire › Dual (CommonJS + ESM) › sinon
Is sinon ESM-only? Can you require() it?
JavaScript test spies, stubs and mocks.
Last verified Sep 9, 2026 against sinon@22.1.0. Markdown · JSON
Dual (CommonJS + ESM) Dual package — require() works on every Node.js version we test; import works too
sinon publishes both a CommonJS entry and a native ESM entry (ESM added in 12.0.0). require("sinon") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "sinon" works alongside it.
What to do
- Nothing to change. require("sinon") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import * as sinon from "sinon" works alongside it; use named imports for what the ESM entry exports.
- TypeScript: npm install -D @types/sinon
Does sinon@22.1.0 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("sinon") from a CommonJS file and import "sinon" from an ES module.
| Runtime | require("sinon") | import "sinon" |
|---|---|---|
| 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 sinon
ES modules (import)
import * as sinon from "sinon";Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.
CommonJS (require)
const sinon = require("sinon");Module format by version
Derived from the type, main and exports fields of every stable release on npm, corrected where a runtime test of that version contradicted them (211 versions; the newest 60 shown).
| Versions | Format | First published |
|---|---|---|
| 12.0.0 – 22.1.0 | Dual (CommonJS + ESM) | Nov 3, 2021 |
| 8.1.1 – 11.1.2 | CommonJS | Jan 22, 2020 |
Frequently asked
Is sinon ESM-only?
sinon@22.1.0 ships CommonJS and ESM builds. sinon publishes both a CommonJS entry and a native ESM entry (ESM added in 12.0.0). require("sinon") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "sinon" works alongside it.
Can I require sinon?
Yes. sinon ships a CommonJS entry alongside the native ESM entry. require("sinon") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun.
Does sinon work in Bun?
Yes. import "sinon" loaded successfully in Bun 1.4.0 on Sep 9, 2026.
Does sinon ship TypeScript types?
Not bundled. Install the community types with "npm install -D @types/sinon".
Links
Other dual (commonjs + esm) packages
- minimatch 10.2.6Dual
- brace-expansion 5.0.9Dual
- lru-cache 11.5.2Dual
- tslib 2.8.1Dual
- glob 13.0.6Dual
- eslint-visitor-keys 5.0.1Dual
- yallist 5.0.0Dual
- balanced-match 4.0.4Dual
Similar popularity
- puppeteer 25.10.0ESM-only
- @nestjs/common 12.0.1ESM-only
- cookie-parser 1.4.7CommonJS
- @babel/plugin-proposal-export-default-from 8.0.1ESM-only
- history 5.3.0CommonJS
- @babel/plugin-proposal-object-rest-spread 7.20.7CommonJS
- webpack-cli 7.2.3CommonJS
- @babel/runtime-corejs3 8.0.0Dual