Repository navigation
fix: hardhat 2 viem resolution mode - #8494
Merged
kanej merged 2 commits intoAug 10, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: 214cf82 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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
force-pushed
the
fix/hardhat-v2-viem-resolution-mode
branch
from
August 6, 2026 19:35
f1a176c to
214cf82
Compare
alcuadrado
approved these changes
Aug 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
hardhat-viemfails to build against the currentviemrelease. A freshpnpm installresolvesviemto a version that ships a nestednode_modules/viem/_types/package.jsoncontaining{"type":"module"}, which did not exist in the version pinned in the committed lockfile.hardhat-viemis a CommonJS package built withmoduleResolution: Node16, and under that resolution mode TypeScript now treatsviem's type declarations as belonging to an ES module. Every top levelimport type { ... } from "viem", and everytypeof import("viem")type query, then needs an explicitresolution-modeimport attribute:We add
with { "resolution-mode": "import" }to the affected type-only imports and type queries inhardhat-viem'ssrcandtestfiles:This is a follow up to #8311, which fixed the same CommonJS/ESM interop problem for
viem's value imports by rewritingawait import("viem")torequire("viem") as typeof import("viem"). That PR did not touch the type-only imports, and predates the_types/package.jsonchange that made those start failing too. We add the same attribute to the type queries in thatrequire/typeof importpattern, 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