canirequire › ESM-only › chai-as-promised
Is chai-as-promised ESM-only? Can you require() it?
Extends Chai with assertions about promises.
Last verified Sep 9, 2026 against chai-as-promised@8.0.2. Markdown · JSON
ESM-only ESM-only since 8.0.0 — last CommonJS version is 7.1.2
chai-as-promised dropped its CommonJS build in 8.0.0 (June 2024). The last version with a plain require()-able CommonJS entry is 7.1.2, published May 11, 2024.
On Node.js 20.19+, 22.12+ and newer, require("chai-as-promised") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 20, 22, 24 and 26. On Node.js 18, which has no require(esm), require("chai-as-promised") fails with ERR_REQUIRE_ESM.
What to do
- On Node.js 20.19+, 22.12+ and newer, require("chai-as-promised") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 20, 22, 24 and 26.
- From a CommonJS file, use a dynamic import inside an async function: const chaiAsPromised = await import("chai-as-promised"). That works on every Node.js version the package supports.
- If you need a synchronous require() or run Node.js 18: npm install chai-as-promised@7.1.2, the last CommonJS release (published May 11, 2024).
- TypeScript: npm install -D @types/chai-as-promised
Does chai-as-promised@8.0.2 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("chai-as-promised") from a CommonJS file and import "chai-as-promised" from an ES module.
| Runtime | require("chai-as-promised") | import "chai-as-promised" |
|---|---|---|
| Node.js 18 | ✗ failsERR_REQUIRE_ESM | ✓ 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 chai-as-promised
ES modules (import)
import * as chaiAsPromised from "chai-as-promised";Namespace import shown because the ESM entry may have no default export; use named imports for what it exports.
CommonJS (require)
// Node.js 20.19+, 22.12+ and newer (verified):
const chaiAsPromised = require("chai-as-promised");
// Any Node.js version the package supports, from an async function:
async function main() {
const chaiAsPromised = await import("chai-as-promised");
}
// Or pin the last CommonJS release:
// npm install chai-as-promised@7.1.2Module 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 (33 versions; the newest 33 shown).
| Versions | Format | First published |
|---|---|---|
| 8.0.0 – 8.0.2 | ESM-only | Jun 9, 2024 |
| 1.0.0 – 7.1.2 | CommonJS | Mar 29, 2012 |
Frequently asked
Is chai-as-promised ESM-only?
chai-as-promised@8.0.2 is ESM-only. chai-as-promised dropped its CommonJS build in 8.0.0 (June 2024). The last version with a plain require()-able CommonJS entry is 7.1.2, published May 11, 2024.
Which version of chai-as-promised still supports CommonJS / require()?
7.1.2 is the last version of chai-as-promised with a CommonJS build. Install it with "npm install chai-as-promised@7.1.2". Every version from 8.0.0 on is ESM-only.
How do I use chai-as-promised from a CommonJS file?
From a CommonJS file, use a dynamic import inside an async function: const chaiAsPromised = await import("chai-as-promised"). That works on every Node.js version the package supports. On Node.js 20.19+, 22.12+ and newer, require("chai-as-promised") works with the latest version: Node.js loads synchronous ES modules through require(). Verified on Node.js 20, 22, 24 and 26. Alternatively pin chai-as-promised@7.1.2.
Does chai-as-promised work in Bun?
Yes. import "chai-as-promised" loaded successfully in Bun 1.4.0 on Sep 9, 2026.
Does chai-as-promised ship TypeScript types?
Not bundled. Install the community types with "npm install -D @types/chai-as-promised".
Links
Other esm-only packages
- ansi-styles 7.0.0last CJS
5.2.0 - strip-ansi 7.2.0last CJS
6.0.1 - commander 15.0.0last CJS
14.0.3 - supports-color 11.0.0last CJS
8.1.1 - chalk 6.0.0last CJS
4.1.2 - string-width 8.2.2last CJS
4.2.3 - ansi-regex 6.3.0last CJS
5.0.1 - escape-string-regexp 5.0.0last CJS
4.0.0
Similar popularity
- react-bootstrap 2.10.10CommonJS
- lerna 10.0.1ESM-only
- browserify 17.0.1CommonJS
- pretty-quick 4.2.2Dual
- @angular/language-service 22.1.5CommonJS
- @vue/eslint-config-typescript 14.9.0Dual
- vuedraggable 2.24.3CommonJS
- shx 0.4.0No entry