fix(build): make messenger, ui and mdx dist resolvable by Node's ESM loader - #11
Merged
Conversation
…loader
These three packages declare "type": "module" with only an exports.import
condition, so Node reads their output as ESM, where relative specifiers need an
explicit extension and a directory never resolves to its index.js. Their builds
were missing tsc-alias's resolveFullPaths, which core and devtools already set,
so dist shipped the shortened forms that only bundlers and CJS accept:
import "./i18n"; // ERR_UNSUPPORTED_DIR_IMPORT
import { logger } from "./logger"; // ERR_MODULE_NOT_FOUND
ui/i18n had a second, independent blocker that resolveFullPaths does not fix: it
imported its English strings from JSON, which Node refuses without a
with { type: "json" } import attribute. That one failed silently rather than
loudly - core reaches the entry through a dynamic import in Game.init wrapped in
a try/catch that treats any failure as "the UI package isn't installed" - so UI
strings degraded to raw translation keys under Node and SSR. The locale is now a
TypeScript module, matching messenger/src/i18n/en.ts; the exported uiTranslations
type is byte-identical to before.
Verified by importing every emitted module of all five packages under plain Node:
209 modules, no resolver errors.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (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.
What was broken
messenger,uiandmdxdeclare"type": "module"with only anexports.importcondition, so Node reads their published output as ESM — where relative specifiers need an explicit file extension and a directory never resolves to itsindex.js. Their builds were missing tsc-alias'sresolveFullPaths, whichcoreanddevtoolsalready set, sodistshipped the shortened forms that only bundlers and CJS accept:Reproducible in two lines against the previously published tarball:
mdxhad the same missing setting and is fixed alongside.The second, quieter bug in
uiresolveFullPathsdoes not fix@react-text-game/ui/i18n: it imported its English strings from JSON, which Node refuses without awith { type: "json" }import attribute (ERR_IMPORT_ATTRIBUTE_MISSING).This one failed silently rather than loudly.
corereaches that entry through a dynamic import insideGame.init, wrapped in atry/catchthat treats any failure as "the UI package isn't installed" (packages/core/src/i18n/utils.ts). So under Node and SSR, UI strings degraded to raw translation keys with nothing logged.The locale is now a TypeScript module, matching the existing
messenger/src/i18n/en.tsprecedent. The exporteduiTranslationsdeclaration is byte-identical to before.Verification
node16/nodenexttypecheck.lint,typecheck,test:coverage,buildandpublintall green; the newui.tsis at 100% coverage and present in LCOV.core's internalloadUITranslations()now returns"Main Menu"instead of{}.Note on ordering
These versions are already on npm (
messenger@0.1.1,ui@0.6.1,mdx@0.3.1), published from this branch. Please merge without squashing so the commit SHA referenced in the CHANGELOG entries (332db0b) stays valid.🤖 Generated with Claude Code