fix: don't fail install when running npm install in an example workspace (#687)#695
Open
d-turley wants to merge 2 commits into
Open
fix: don't fail install when running npm install in an example workspace (#687)#695d-turley wants to merge 2 commits into
d-turley wants to merge 2 commits into
Conversation
npm runs the root `prepare` script on every `npm install`, including when installing a single workspace example via `npm install` inside `examples/<name>`. That flow does not install the root package's devDependencies, so `prepare`'s `npm run build` crashed with a cryptic `ERR_MODULE_NOT_FOUND: ts-to-zod`. Move `prepare` into scripts/prepare.mjs, which skips the SDK build with a helpful message when the build toolchain is missing instead of failing the install. Registry consumers are unaffected (prepare does not run for published packages and dist/ ships in the tarball); git installs still build because npm installs a git dependency's devDependencies before running prepare. Refs modelcontextprotocol#687 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The examples are npm workspaces of the repository root. Running `npm install` inside an example directory triggers the root `prepare` build without the root devDependencies installed, which fails (issue modelcontextprotocol#687). Update the example READMEs to install from the repository root (which installs all workspaces and builds the SDK), then run the example from its directory. Refs modelcontextprotocol#687 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes #687.
Following an example's README literally — e.g.:
cd examples/basic-host npm installfails with a cryptic error:
Root cause
examples/*are npm workspaces of the repository root. Runningnpm installinside an example directory makes npm install only that workspace's dependencies
(it does not install the root package's
devDependenciessuch asts-to-zod,bun,tsx,esbuild), yet npm still runs the root package'spreparescript(
npm run build && husky). The build immediately runsgenerate:schemas→tsx scripts/generate-schemas.ts, which imports the missingts-to-zodand crashes. This affects every example, not justbasic-host.Changes
Guard the
preparebuild — move it intoscripts/prepare.mjs, which skipsthe SDK build with a clear, actionable message when the build toolchain isn't
installed (i.e. a workspace-child/partial install) instead of failing with an
opaque
ERR_MODULE_NOT_FOUND. A full install from the repo root still buildsas before.
preparedoesn't run for publishedpackages and
dist/ships in the tarball.devDependenciesbefore running itsprepare.Docs — update the example READMEs' setup instructions to install from the
repository root (which installs all workspaces and builds the SDK the examples
import), then run the example from its directory.
Testing
In a clean checkout on Windows:
cd examples/basic-host && npm install— before: exit 1,ERR_MODULE_NOT_FOUND: ts-to-zod; after: exit 0 with:[prepare] Skipping SDK build: missing build tooling (ts-to-zod, bun). ... run npm install from the repository root.npm installfrom the repository root — still runs the full build(
generate:schemas+sync:snippets+ bundle), exits 0, and producesdist/.🤖 Generated with Claude Code