fix(node-sdk): declare @x402/fetch as an optional peer dependency - #191
Open
rohitsux wants to merge 1 commit into
Open
fix(node-sdk): declare @x402/fetch as an optional peer dependency#191rohitsux wants to merge 1 commit into
rohitsux wants to merge 1 commit into
Conversation
The node SDK's hand-written wrapper (src/wrapper/x402.ts and src/wrapper/Client.ts) lazily imports @x402/fetch for the opt-in payments feature, but the package was not declared anywhere in package.json. That makes it a phantom optional dependency: bundlers fail with unresolvable-import errors, file tracers cannot materialize the dependency closure, and isolated installers (pnpm, bun) guarantee phantom resolution never works. The wrapper even ships a local module declaration (src/wrapper/x402-types.d.ts) to paper over TypeScript being unable to resolve the undeclared package. package.json in agentmail-node is Fern-generated and not covered by .fernignore, so the durable fix lives here in the generator config: extraPeerDependencies plus extraPeerDependenciesMeta mark @x402/fetch as an optional peer, keeping the payments feature opt-in while letting every toolchain see and resolve the import. All published @x402/fetch versions are 2.x, matching the caret range.
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.
Fixes agentmail-to/agentmail-node#24.
Problem
The node SDK's wrapper lazily imports
@x402/fetch(src/wrapper/x402.ts,src/wrapper/Client.ts) for the opt-in payments feature, but the package is not declared anywhere inpackage.json. As the issue lays out, that phantom dependency breaks bundlers (unresolvable-import errors), file tracers such as@vercel/nft(a configured external must be resolvable on disk), and isolated installers (pnpm, bun), forcing consumers to carry externalization workarounds. The wrapper's ownsrc/wrapper/x402-types.d.tsmodule shim exists precisely because TypeScript cannot resolve the undeclared package.Why the fix is here and not in agentmail-node
package.jsonin agentmail-node is Fern-generated and not listed in.fernignore, so declaring the dependency there directly would be overwritten on the next regeneration. The generator config in this repo is the durable layer: thepackageJsonblock's fields (description, keywords, license) already flow into the published package, and the TypeScript generator supportsextraPeerDependencies/extraPeerDependenciesMetafor exactly this case.Change
This keeps payments opt-in (consumers install
@x402/fetchonly if they use the feature) while making the import visible to every toolchain. All published@x402/fetchversions are 2.x, and the wrapper uses onlyx402HTTPClientandwrapFetchWithPayment, both stable across 2.x.Verification
npx fern-api check: 0 errors, 9 warnings — identical to unmodifiedmain(the warnings are pre-existing).Follow-up (out of scope here)
Once this is released,
src/wrapper/x402-types.d.tsin agentmail-node could be dropped in favor of the real types from the now-resolvable package.