Skip to content

fix: use static JSON imports in ESM entry for bundler compatibility#6

Merged
zkochan merged 2 commits intomainfrom
fix-esm-static-imports
Mar 24, 2026
Merged

fix: use static JSON imports in ESM entry for bundler compatibility#6
zkochan merged 2 commits intomainfrom
fix-esm-static-imports

Conversation

@zkochan
Copy link
Copy Markdown
Member

@zkochan zkochan commented Mar 24, 2026

Summary

  • Replace createRequire + require('./allow.json') with static import ... with { type: 'json' } in index.mjs
  • createRequire(import.meta.url) resolves paths relative to the importing file's URL, which breaks when bundled by esbuild — the JSON files don't exist next to the bundle output
  • Static import attributes allow bundlers to inline the JSON at build time

Test plan

  • CJS tests pass (8/8)
  • ESM tests pass (2/2)

zkochan added 2 commits March 24, 2026 18:36
createRequire resolves paths relative to import.meta.url, which
breaks when the module is bundled (e.g., by esbuild) because the
JSON files don't exist next to the bundle output. Static import
with { type: 'json' } allows bundlers to inline the JSON data.
ESLint's default parser doesn't support import attributes
(with { type: 'json' }) syntax yet.
@zkochan zkochan merged commit 801bcab into main Mar 24, 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.

1 participant