Skip to content

fix(dictionaries-entry): use readdir for ESM/Vite compatibility#401

Merged
aymericzip merged 2 commits intoaymericzip:mainfrom
modanub:fix/dictionaries-entry-esm-compat
Mar 22, 2026
Merged

fix(dictionaries-entry): use readdir for ESM/Vite compatibility#401
aymericzip merged 2 commits intoaymericzip:mainfrom
modanub:fix/dictionaries-entry-esm-compat

Conversation

@modanub
Copy link
Copy Markdown
Contributor

@modanub modanub commented Mar 22, 2026

Summary

Follow-up to #400. The vm.runInThisContext approach passes require to execute CJS entry points, which breaks in Vite/ESM environments where require isn't available:

Calling `require` for "../dictionary/app.json" in an environment that
doesn't expose the `require` function.

Replaces the CJS entry point execution with direct JSON file reading via readdirSync + readFileSync + JSON.parse. No require(), no vm, works in both CJS and ESM.

Memory leak fix from #400 is preserved (still ~1KB/call).

Test plan

  • All packages build (42/42)
  • vite-react-app build
  • vite-preact-app build
  • vite-vue-app build
  • vite-svelte-app build
  • vite-solid-app build
  • nextjs-15-app build
  • ESM output has zero require() calls
  • Memory leak benchmark unchanged (~1KB/call)

…or ESM compat

The previous approach passed require to execute CJS entry points via
vm.runInThisContext, which breaks in Vite/ESM where require is unavailable.

Read JSON files directly from the dictionary output directory instead.
No require(), no vm, works in both CJS and ESM environments.
@aymericzip aymericzip merged commit 8df8f7b into aymericzip:main Mar 22, 2026
1 check passed
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.

2 participants