fix: add serverExternalPackages to Next.js template for bundler compatibility#1024
Open
mvanhorn wants to merge 1 commit intocoinbase:mainfrom
Open
fix: add serverExternalPackages to Next.js template for bundler compatibility#1024mvanhorn wants to merge 1 commit intocoinbase:mainfrom
mvanhorn wants to merge 1 commit intocoinbase:mainfrom
Conversation
…tibility Next.js 16 (Turbopack and Webpack) breaks when bundling @noble/hashes for server-side rendering. The ESM exports of @noble/hashes get incorrectly tree-shaken, causing "TypeError: Y is not a function" at runtime when keccak256 is called via viem. Adding these packages to serverExternalPackages tells Next.js to skip bundling them and use Node.js require() instead, which resolves the ESM/CJS interop issue.
🟡 Heimdall Review Status
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Adds
serverExternalPackagesto thecreate-onchain-agentNext.js template to fix build failures with Next.js 16 (Turbopack and Webpack).Closes #929
Problem
Next.js 16's Turbopack aggressively bundles server-side dependencies including
@noble/hashes. The ESM exports get incorrectly tree-shaken during bundling, causing a runtimeTypeError: Y is not a functionwhenkeccak256is called viaviem(a transitive dependency of AgentKit).The error appears at build time during page data collection:
This affects both Turbopack and Webpack bundlers in Next.js 16.
Solution
Adding
@noble/hashes,@noble/curves,@scure/bip39, and@scure/bip32toserverExternalPackagesinnext.config.jstells Next.js to skip bundling these packages and use Node.jsrequire()instead. This avoids the ESM/CJS interop issue that breaks the crypto libraries.The fix is applied to
typescript/create-onchain-agent/templates/next/next.config.jsso all new projects created withnpm create onchain-agent@latestget the correct config.Users with existing projects should add the same config:
Tests
This is a configuration change in the project template. The fix was verified by reproducing the issue described in #929 and confirming the build succeeds with
serverExternalPackagesset.Checklist
This contribution was developed with AI assistance (Claude Code).