canirequire › ESM-only › hardhat
Is hardhat ESM-only? Can you require() it?
Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
Last verified Sep 9, 2026 against hardhat@3.16.0. JSON
ESM-only ESM-only since 3.0.0 — last CommonJS version is 2.29.1
hardhat dropped its CommonJS build in 3.0.0 (August 2025). The last version you can require() on every Node.js version, including 18 and older, is 2.29.1, published Aug 18, 2026.
require("hardhat") fails even on Node.js 20.19+ / 22.12+ because the package uses top-level await, which require(esm) cannot load. Use import() instead.
Does hardhat@3.16.0 actually load? Runtime test results
Installed and executed on Sep 9, 2026 with require("hardhat") from a CommonJS file and import "hardhat" from an ES module.
| Runtime | require("hardhat") | import "hardhat" |
|---|---|---|
| Node.js 18 | ✗ failsERR_REQUIRE_ESM | ✗ failsSyntaxError |
| Node.js 20 | ✗ failsERR_REQUIRE_ASYNC_MODULE | ✗ failsHardhatError |
| Node.js 22 | ✗ failsERR_REQUIRE_ASYNC_MODULE | ✗ failsHardhatError |
| Node.js 24 | ✗ failsERR_REQUIRE_ASYNC_MODULE | ✗ failsHardhatError |
| Node.js 26 | ✗ failsERR_REQUIRE_ASYNC_MODULE | ✗ failsHardhatError |
| Bun 1.4 | ✗ failsTypeError | ✗ failsHardhatError |
How to import hardhat
ES modules (import)
import hardhat from "hardhat";CommonJS (require)
// Node.js 20.19+ / 22.12+ / newer (package has no top-level await):
const hardhat = require("hardhat");
// Any Node.js version:
const hardhat = await import("hardhat");
// Or pin the last CommonJS release:
// npm install hardhat@2.29.1Module format by version
Derived from the type, main and exports fields of every stable release on npm (196 versions; the newest 60 shown).
| Versions | Format | First published |
|---|---|---|
| 3.0.0 – 3.16.0 | ESM-only | Aug 13, 2025 |
| 2.28.3 – 2.29.1 | CommonJS | Jan 8, 2026 |
Frequently asked
Is hardhat ESM-only?
hardhat@3.16.0 is ESM-only. hardhat dropped its CommonJS build in 3.0.0 (August 2025). The last version you can require() on every Node.js version, including 18 and older, is 2.29.1, published Aug 18, 2026.
Which version of hardhat still supports CommonJS / require()?
2.29.1 is the last version of hardhat with a CommonJS build. Install it with "npm install hardhat@2.29.1". Every version from 3.0.0 on is ESM-only.
How do I use hardhat from a CommonJS file?
Use a dynamic import: const mod = await import("hardhat"). On Node.js 20.19+, 22.12+ and newer, a plain require("hardhat") also works for ESM packages that do not use top-level await. Alternatively pin hardhat@2.29.1.
Does hardhat work in Bun?
Importing hardhat failed in Bun 1.4 on Sep 9, 2026: HardhatError: HHE3: No Hardhat config file found.
Does hardhat ship TypeScript types?
Yes. hardhat bundles its own type declarations; no @types package is needed.
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 - tslib 2.8.1last CJS
2.5.2 - string-width 8.2.2last CJS
4.2.3 - ansi-regex 6.3.0last CJS
5.0.1
Similar popularity
- grunt-contrib-copy 1.0.0CommonJS
- bower 1.8.14CommonJS
- karma-spec-reporter 0.0.37CommonJS
- react-native-builder-bob 0.43.1ESM-only
- rewire 9.0.1CommonJS
- codecov 3.8.3CommonJS
- grunt-contrib-uglify 5.2.2CommonJS
- pre-commit 2.0.0CommonJS