Skip to content

fix(parsers): inline directive JSON into bundle to stop srv-qa boot crash - #3042

Closed
jung-thomas wants to merge 1 commit into
DEVfrom
fix-srv-qa-json-bundle-crash
Closed

jung-thomas wants to merge 1 commit into
DEVfrom
fix-srv-qa-json-bundle-crash

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

Problem

A DEV deploy failed at cf deploy: tutorials-srv-qa crashes on start, exhausting all 3 MTA retries. App log:

uncaughtException: Cannot find module './icon-allowlist.json'
Require stack:
- /home/vcap/app/srv/lib/parsers.bundle.mjs

Root cause

Commit 2adeeb33c switched scripts/parsers/directives/ui.ts from a static import iconAllowlist from './icon-allowlist.json' with { type: 'json' } to a runtime createRequire(import.meta.url)('./icon-allowlist.json').

esbuild inlines static JSON imports into parsers.bundle.mjs but leaves runtime requires external. The externalized require('./icon-allowlist.json') resolves relative to gen/srv-qa/srv/lib/, where the JSON is never copied → MODULE_NOT_FOUND → boot crash → deploy fail.

reference-links.ts had the same latent pattern for api-libs.json (a second time bomb in the same bundle).

Fix

Use static default imports for both JSON files (resolveJsonModule: true is already set), so esbuild inlines them into the bundle — nothing external to ship.

Verification

  • Rebuilt parsers.bundle.mjs: grep finds no residual require('./icon-allowlist.json') or require('./api-libs.json').
  • Positive check: icon-allowlist.json values are present inline in the bundle.
  • Directive unit tests: 19/19 pass (vitest run scripts/parsers/directives).

Source-only change (2 .ts files); the bundle is gitignored and rebuilt at deploy time.

🤖 Generated with Claude Code

…rash

tutorials-srv-qa crashed on start with MODULE_NOT_FOUND
'./icon-allowlist.json' (required by srv/lib/parsers.bundle.mjs), failing
the MTA deploy.

Root cause: commit 2adeeb3 switched ui.ts's icon-allowlist.json load from
a static `import ... with { type: 'json' }` to a runtime createRequire().
esbuild bundles static JSON imports but leaves runtime requires external, so
the bundled parsers.bundle.mjs referenced a sibling file that is never copied
into gen/srv-qa/srv/lib/. reference-links.ts had the same latent pattern for
api-libs.json.

Fix: use static default imports (resolveJsonModule is on) so esbuild inlines
both JSON files into the bundle — no external file to ship.

Verified: rebuilt bundle has no residual require() of either JSON; the
icon-allowlist values are present inline; directive unit tests pass (19/19).
@jung-thomas

Copy link
Copy Markdown
Contributor Author

Superseded by 81d6757 (already merged to DEV) which applies the identical static-JSON-import fix to both ui.ts and reference-links.ts. Closing as redundant.

@jung-thomas jung-thomas closed this Nov 6, 2026
@jung-thomas
jung-thomas deleted the fix-srv-qa-json-bundle-crash branch November 6, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant