Skip to content

fix: hardhat 2 viem resolution mode - #8494

Merged
kanej merged 2 commits into
hardhat-v2-update-prettierfrom
fix/hardhat-v2-viem-resolution-mode
Aug 10, 2026
Merged

kanej merged 2 commits into
hardhat-v2-update-prettierfrom
fix/hardhat-v2-viem-resolution-mode

Conversation

@kanej

@kanej kanej commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

hardhat-viem fails to build against the current viem release. A fresh pnpm install resolves viem to a version that ships a nested node_modules/viem/_types/package.json containing {"type":"module"}, which did not exist in the version pinned in the committed lockfile. hardhat-viem is a CommonJS package built with moduleResolution: Node16, and under that resolution mode TypeScript now treats viem's type declarations as belonging to an ES module. Every top level import type { ... } from "viem", and every typeof import("viem") type query, then needs an explicit resolution-mode import attribute:

error TS1541: Type-only import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.

We add with { "resolution-mode": "import" } to the affected type-only imports and type queries in hardhat-viem's src and test files:

import type { Address } from "viem" with { "resolution-mode": "import" };

This is a follow up to #8311, which fixed the same CommonJS/ESM interop problem for viem's value imports by rewriting await import("viem") to require("viem") as typeof import("viem"). That PR did not touch the type-only imports, and predates the _types/package.json change that made those start failing too. We add the same attribute to the type queries in that require/typeof import pattern, and to the equivalent value imports in the test files, which #8311 did not cover.

Manual testing

To run the changes locally:

rm pnpm-lock.yaml
pnpm install --no-frozen-lockfile
pnpm build
pnpm --filter @nomicfoundation/hardhat-viem test

@kanej kanej added no docs needed This PR doesn't require links to documentation no peer bump needed labels Aug 6, 2026
@changeset-bot

changeset-bot Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 214cf82

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@nomicfoundation/hardhat-viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kanej kanej changed the title Fix/hardhat v2 viem resolution mode fix: hardhat v2 viem resolution mode Aug 6, 2026
@kanej kanej changed the title fix: hardhat v2 viem resolution mode fix: hardhat 2 viem resolution mode Aug 6, 2026
kanej added 2 commits August 6, 2026 19:32
A fresh install resolves viem to a release that ships a nested
_types/package.json with type: module, which makes TypeScript treat
viem's type declarations as belonging to an ES module. Under this
package's CommonJS/Node16 setup, every type-only import from viem
then needs an explicit resolution-mode import attribute, or tsc
fails with TS1541/TS1542.

Add the attribute to the affected type-only imports and type
queries in src and test. No dependency version changes, so this
stays compatible with both the currently pinned viem and future
releases.
@kanej
kanej force-pushed the fix/hardhat-v2-viem-resolution-mode branch from f1a176c to 214cf82 Compare August 6, 2026 19:35
@kanej
kanej changed the base branch from hardhat-v2-update-prettier to v2 August 7, 2026 08:44
@kanej
kanej changed the base branch from v2 to hardhat-v2-update-prettier August 7, 2026 08:51
@kanej
kanej requested a review from alcuadrado August 7, 2026 09:41
@kanej
kanej merged commit 5ef73ac into v2 Aug 10, 2026
2 checks passed
@kanej
kanej deleted the fix/hardhat-v2-viem-resolution-mode branch August 10, 2026 08:29
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no docs needed This PR doesn't require links to documentation no peer bump needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants