Repository navigation
fix(bundler): force-include every OTel devDep + CI smoke-test the packed tarball - #3683
Merged
Merged
Conversation
decocms 2.393.0 shipped with @opentelemetry/sdk-metrics missing from dist/server/node_modules/, so every consumer crashed at startup with: Cannot find module '@opentelemetry/sdk-metrics' from /app/apps/mesh/node_modules/decocms/dist/server/cli.js Root cause: `bun build --target bun` auto-externalizes every node_modules import, and the bundler relies on @vercel/nft to trace + copy the package files into dist/server/node_modules/. OTel v2 packages use conditional exports + lazy requires that nft can't follow statically. When nft drops one, the bundle still emits `from "@opentelemetry/..."` for it, and the published cli.js can't resolve it at startup. The existing ALWAYS_INCLUDE entry for @opentelemetry/resources was already the manual escape hatch for one such failure. Extending it to every OTel package the runtime imports closes the same hole for the rest. Adds verifyBundlesShipExternals() that runs at the end of the build and fails it if any ALWAYS_INCLUDE entry didn't make it to disk, or if any external @opentelemetry/* import in the bundles has no shipped package. Scoped to @opentelemetry/* via STRICT_SHIPPING_PREFIXES so it doesn't false-positive on consumer-installed deps like pg / react / node-fetch that resolve via decocms's runtime dependencies tree. Co-Authored-By: Claude Opus 4.7 <[email protected]>
Contributor
🧪 BenchmarkShould we run the Virtual MCP strategy benchmark for this PR? React with 👍 to run the benchmark.
Benchmark will run on the next push after you react. |
Backstop for the decocms 2.393.0 incident — install the just-packed tarball into a scratch dir exactly the way a consumer would (`bun add decocms@<ver>`), then `bun cli.js --version`. Because bun emits ESM `from "pkg"` for externals, loading cli.js eagerly resolves every top-level external before --version ever prints — a missing one (e.g. nft dropped an OTel package) crashes here with "Cannot find module …". The static-side defense in apps/mesh/scripts/bundle-server-script.ts (verifyBundlesShipExternals) catches the same failure at build time without npm publish in the picture. This step is the publish-time backstop that also catches failure modes the static check can't (files-field stripping, prepublishOnly side-effects, signing weirdness). Runs after `npm pack`, before `upload-artifact` — a failure stops the mesh-package artifact from being produced, so publish-npm and build-docker never see the bad bytes. Co-Authored-By: Claude Opus 4.7 <[email protected]>
…fier to direct-resolvable strict deps
The first pass at the OTel ship-everything fix listed transitive-only
packages (context-async-hooks, otlp-exporter-base, otlp-transformer,
semantic-conventions) in ALWAYS_INCLUDE. Bun's isolated install puts those
under node_modules/.bun/<pkg>@<ver>/... and only surfaces direct deps at
apps/mesh/node_modules/, so Bun.resolveSync() — which is how the bundler
turns ALWAYS_INCLUDE entries into nft entry points — couldn't find them
and failed the build:
❌ Failed to resolve @opentelemetry/context-async-hooks: error: Cannot
find module '@opentelemetry/context-async-hooks' from '…/apps/mesh'
Direct deps only. Transitives get picked up by nft as it walks from the
direct entries — verified by inspecting the 2.393.0 tarball, which
shipped context-async-hooks and otlp-exporter-base despite neither being
direct deps. The runtime-resolution check (next paragraph) catches any
@opentelemetry/* package the bundle references but doesn't ship, so
demoting an entry from ALWAYS_INCLUDE to transitive isn't a silent
regression vector.
While here, narrow verifyBundlesShipExternals():
- Drop the "every ALWAYS_INCLUDE entry must be shipped" invariant.
React is in ALWAYS_INCLUDE as an nft entry point but it's also a
runtime `dependency`, so the consumer install brings it in and the
bundler never copies it. The invariant was false for the existing
code, not just for the entries I added.
- Exempt runtime `dependencies` from the strict @opentelemetry/* check.
@opentelemetry/core is in the runtime dependencies list, so even if
it's somehow absent from dist/server/node_modules/, the consumer's
install resolves it.
Locally builds clean now: bun run --cwd=apps/mesh build:server prints
"✅ Bundle externalization OK — every @opentelemetry/* import resolves."
and dist/server/node_modules/@opentelemetry/ contains sdk-metrics,
sdk-node, exporter-prometheus, instrumentation-runtime-node, plus the
transitively-traced otlp-transformer and semantic-conventions.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
Two follow-up fixes from the first CI run on this PR:
1. release-mesh.yaml smoke test referenced cli.js by its raw bundle
path (`bun ./node_modules/decocms/dist/server/cli.js --version`),
which tripped knip's "unlisted binaries" check. Use the `deco` bin
name (from decocms's `bin` field in package.json) so knip can
resolve the reference: `./node_modules/.bin/deco --version`. The
check still runs against the same compiled file — the bin is just
a renamed entry point.
2. apps/mesh/src/tools/eventbus/schema.ts had a stray double blank
line introduced by an earlier commit on this branch
(e6d6b4d "fix(event-bus): remove unused SubscriptionEntity
export"). Local `bun run fmt` caught it; commit it so format:check
in CI passes.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
…riendly) The previous attempt invoked the deco bin straight from the workflow YAML (`./node_modules/.bin/deco --version`), which knip's "unlisted binaries" check flagged because knip scans workflow `run:` blocks for bare binary names and doesn't know `deco` comes from the package we're publishing. Per the repo's "never silence knip" policy, hide the bin behind a TS shim — same pattern as the existing scripts/smoke-link.ts. The shim still runs the bin, just via `bun run scripts/smoke-tarball.ts`, which knip is happy with. Catches the #2.393.0 failure exactly the same way: ESM bundle's top-level imports execute eagerly on load, so a missing external still crashes before --version prints. Co-Authored-By: Claude Opus 4.7 <[email protected]>
decocms Bot
pushed a commit
that referenced
this pull request
Jun 4, 2026
PR: #3683 fix(bundler): force-include every OTel devDep + CI smoke-test the packed tarball Bump type: patch - decocms (apps/mesh/package.json): 2.393.4 -> 2.393.5
5 of 6 tasks
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
dist/server/cli.jsthat doesfrom "@opentelemetry/sdk-metrics"(and other OTel externals) without shipping the package indist/server/node_modules/. Every consumer (npm install + Docker image) crashes at startup:bun build --target bunauto-externalizes everynode_modules/import. The bundler relies on@vercel/nftto trace + copy the package files. OTel v2 packages use conditional exports + lazy requires that nft can't follow — so it silently drops the package, and the bundle then crashes at runtime because the externalizedfrom "..."resolves to nothing. The pre-existingALWAYS_INCLUDEentry for@opentelemetry/resourceswas already the manual escape hatch for one instance of this; this PR extends it to every OTel package the runtime imports.fix(bundler): …commit). AddsverifyBundlesShipExternals()tobundle-server-script.ts. Fails the build if (a) anyALWAYS_INCLUDEentry didn't make it to disk, or (b) any external@opentelemetry/*import incli.js/server.js/migrate.jshas no shipped package. Scoped to@opentelemetry/*viaSTRICT_SHIPPING_PREFIXESso it doesn't false-positive on consumer-installed deps (pg,react,node-fetch, …) that the consumer's install resolves via decocms's runtimedependenciestree.ci(release-mesh): …commit). Afternpm pack, install the just-packed tarball in a scratch dir (bun add file://…/decocms-*.tgz) and runbun cli.js --version. Because bun emits ESMfrom "pkg"for externals, top-level external resolution is eager — a missing one crashes before--versionprints. Runs before artifact upload, sopublish-npm+build-dockernever see a broken artifact. Also catches publish-time failure modes the static check can't (files-field filtering, prepublishOnly side-effects, signing weirdness).Evidence the fix maps to the bug
Diffed published tarballs (
npm pack [email protected] / 2.393.0):@opentelemetry/sdk-metricsRan the new
verifyBundlesShipExternalslogic against the broken 2.393.0cli.js: it flags@opentelemetry/sdk-metricsand only that — no false positives.Out of scope (your hands)
latesttag rollback + Docker image repoint require registry writes you'll want to do consciously:npm dist-tag add [email protected] latestnpm deprecate [email protected] "Missing @opentelemetry/sdk-metrics — use 2.392.0 until 2.394.0 ships"mesh:2.393.0Test plan
bun run --cwd=apps/mesh build:server✅ Bundle externalization OK — ALWAYS_INCLUDE + every @opentelemetry/* import is shipped.apps/mesh/dist/server/node_modules/@opentelemetry/sdk-metrics/package.jsonexists after buildcd apps/mesh && npm pack && SCRATCH=$(mktemp -d) && (cd "$SCRATCH" && printf '{"name":"smoke","version":"0.0.0","private":true}\n' > package.json && bun add "$OLDPWD"/decocms-*.tgz && bun ./node_modules/decocms/dist/server/cli.js --version)— should print a version, not "Cannot find module"Smoke-test the packed tarballstep passeslatestnpm tag to 2.392.0 and repoint the Docker GitOps tag🤖 Generated with Claude Code