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. Markdown · 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 with a plain require()-able CommonJS entry is 2.29.1, published Aug 18, 2026.
require("hardhat") fails even on Node.js 20.19+, 22.12+ and newer: the package uses top-level await, which require(esm) cannot load (ERR_REQUIRE_ASYNC_MODULE). Use import() instead. On Node.js 18, which has no require(esm), require("hardhat") fails with ERR_REQUIRE_ESM.
What to do
- require("hardhat") fails even on Node.js 20.19+, 22.12+ and newer: the package uses top-level await, which require(esm) cannot load (ERR_REQUIRE_ASYNC_MODULE). Use import() instead.
- From a CommonJS file, use a dynamic import inside an async function: const hardhat = await import("hardhat"). That works on every Node.js version the package supports.
- If you need a synchronous require() or run Node.js 18: npm install hardhat@2.29.1, the last CommonJS release (published Aug 18, 2026).
- TypeScript: types are bundled; install nothing extra.
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.0 | ✗ failsTypeError | ✗ failsHardhatError |
How to import hardhat
ES modules (import)
import * as hardhat from "hardhat";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 cannot require() this package: it uses top-level await.
// Any Node.js version the package supports, from an async function:
async function main() {
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, corrected where a runtime test of that version contradicted them (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 with a plain require()-able CommonJS entry 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?
From a CommonJS file, use a dynamic import inside an async function: const hardhat = await import("hardhat"). That works on every Node.js version the package supports. require("hardhat") fails even on Node.js 20.19+, 22.12+ and newer: the package uses top-level await, which require(esm) cannot load (ERR_REQUIRE_ASYNC_MODULE). Use import() instead. Alternatively pin hardhat@2.29.1.
Does hardhat work in Bun?
Importing hardhat failed in Bun 1.4.0 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 - 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
- bower 1.8.14CommonJS
- karma-spec-reporter 0.0.37CommonJS
- react-native-builder-bob 0.43.1ESM-only
- @vue/cli-service 5.0.9CommonJS
- rewire 9.0.1CommonJS
- codecov 3.8.3CommonJS
- grunt-contrib-uglify 5.2.2CommonJS
- pre-commit 2.0.0CommonJS