canirequire

canirequire › CommonJS › @nomiclabs/hardhat-ethers

Is @nomiclabs/hardhat-ethers ESM-only? Can you require() it?

Hardhat plugin for ethers

Last verified Sep 9, 2026 against @nomiclabs/hardhat-ethers@2.2.3. Markdown · JSON

CommonJS CommonJS on paper — require() failed in our runtime test

@nomiclabs/hardhat-ethers declares a CommonJS entry only, but require("@nomiclabs/hardhat-ethers") failed on every Node.js version in our probe: HardhatError: HH5: HardhatContext is not created. import "@nomiclabs/hardhat-ethers" resolves to the same file, so it fails the same way. That usually means a missing peer dependency, a browser-only global, or a package that is not meant to be loaded directly; see the runtime table below.

What to do

  1. require("@nomiclabs/hardhat-ethers") failed in our probe on every Node.js version (HardhatError: HH5: HardhatContext is not created); check the package README for peer dependencies or setup before relying on it.
  2. From ES modules use the default import: import hardhatEthers from "@nomiclabs/hardhat-ethers"; then destructure. Named imports only work when Node.js can statically detect the exports.
  3. TypeScript: types are bundled; install nothing extra.
Latest
2.2.3 (Apr 10, 2023)
Module format
CommonJS
Last CommonJS version
2.2.3
TypeScript types
Bundled
Node engines
not declared
Weekly downloads
99K
License
MIT

Does @nomiclabs/hardhat-ethers@2.2.3 actually load? Runtime test results

Installed and executed on Sep 9, 2026 with require("@nomiclabs/hardhat-ethers") from a CommonJS file and import "@nomiclabs/hardhat-ethers" from an ES module.

Runtimerequire("@nomiclabs/hardhat-ethers")import "@nomiclabs/hardhat-ethers"
Node.js 18✗ failsHardhatError✗ failsHardhatError
Node.js 20✗ failsHardhatError✗ failsHardhatError
Node.js 22✗ failsHardhatError✗ failsHardhatError
Node.js 24✗ failsHardhatError✗ failsHardhatError
Node.js 26✗ failsHardhatError✗ failsHardhatError
Bun 1.4.0✗ failsHardhatError✗ failsHardhatError

A failing require() on a CommonJS package usually means the package needs a browser/DOM global, a peer dependency, or a native binary that is not available in a bare Node.js process.

How to import @nomiclabs/hardhat-ethers

ES modules (import)

import hardhatEthers from "@nomiclabs/hardhat-ethers";

Named imports from a CommonJS package only work when Node.js can statically detect them. If a named import fails, use the default import and destructure.

CommonJS (require)

// require("@nomiclabs/hardhat-ethers") failed in our probe on every Node.js version we test (HardhatError: HH5: HardhatContext is not created); see the runtime table.
const hardhatEthers = require("@nomiclabs/hardhat-ethers");

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 (14 versions; the newest 14 shown).

VersionsFormatFirst published
1.0.0 – 2.2.3CommonJSOct 22, 2020

Frequently asked

Is @nomiclabs/hardhat-ethers ESM-only?

@nomiclabs/hardhat-ethers@2.2.3 declares a CommonJS entry, but require() fails at runtime. @nomiclabs/hardhat-ethers declares a CommonJS entry only, but require("@nomiclabs/hardhat-ethers") failed on every Node.js version in our probe: HardhatError: HH5: HardhatContext is not created. import "@nomiclabs/hardhat-ethers" resolves to the same file, so it fails the same way. That usually means a missing peer dependency, a browser-only global, or a package that is not meant to be loaded directly; see the runtime table below.

Can I require @nomiclabs/hardhat-ethers?

Not in practice. @nomiclabs/hardhat-ethers declares a CommonJS entry, but require("@nomiclabs/hardhat-ethers") failed on every Node.js version in our probe: HardhatError: HH5: HardhatContext is not created. Check the package README for peer dependencies or setup before relying on it.

Can I import @nomiclabs/hardhat-ethers with ES module syntax?

Yes. import hardhatEthers from "@nomiclabs/hardhat-ethers" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

Does @nomiclabs/hardhat-ethers work in Bun?

Importing @nomiclabs/hardhat-ethers failed in Bun 1.4.0 on Sep 9, 2026: HardhatError: HH5: HardhatContext is not created.

Does @nomiclabs/hardhat-ethers ship TypeScript types?

Yes. @nomiclabs/hardhat-ethers bundles its own type declarations; no @types package is needed.

Links

Other commonjs packages

Similar popularity