Skip to content

fix: replace ESM JSON import attributes with createRequire for Vite compatibility - #3

Merged
aaronlippold merged 1 commit into
hdf-libs-developmentfrom
fix/esm-json-imports-v2
Feb 23, 2026
Merged

fix: replace ESM JSON import attributes with createRequire for Vite compatibility#3
aaronlippold merged 1 commit into
hdf-libs-developmentfrom
fix/esm-json-imports-v2

Conversation

@aaronlippold

Copy link
Copy Markdown
Member

Summary

  • Replace all import ... with { type: 'json' } with createRequire(import.meta.url) across hdf-mappings, hdf-validators, and hdf-converters
  • Remove verbatimModuleSyntax from tsconfig.base.json (was forcing TS to emit import attributes that Vite SSR strips)
  • Add ./package.json export to hdf-converters for self-reference import

Problem

Vite SSR strips with { type: 'json' } import attributes during plugin analysis (RFC #18534), leaving bare JSON imports that Node.js rejects with Module needs an import attribute of "type: json". This breaks any Nuxt/Vite consumer of hdf-libs.

Solution

createRequire(import.meta.url) is the standard portable ESM pattern for loading JSON — works in Node.js, Vite SSR, and all bundlers.

Test plan

  • All 448+ existing tests pass
  • All lint passes
  • Build succeeds with no with { type in dist output
  • JSON data files correctly copied to dist
  • Verify pnpm dev works in heimdall-enterprise consumer after submodule update

…ompatibility

Vite SSR strips `with { type: 'json' }` import attributes during transform
(RFC #18534), breaking any Nuxt/Vite consumer. Replace all JSON import
attributes with `createRequire(import.meta.url)` — the standard portable
ESM pattern that works in Node.js, Vite SSR, and all bundlers.

Changes:
- Remove verbatimModuleSyntax from tsconfig.base.json
- Convert 9 hdf-mappings JSON imports to createRequire
- Convert 9 hdf-validators schema imports to createRequire
- Convert hdf-converters nessus package.json import to createRequire
- Add ./package.json export to hdf-converters for self-reference import

All 434 tests pass. No import attributes remain in dist output.

Authored by: Aaron Lippold<lippold@gmail.com>

Signed-off-by: Aaron Lippold <lippold@gmail.com>
Copilot AI review requested due to automatic review settings February 23, 2026 23:22
@aaronlippold
aaronlippold merged commit 563a1c6 into hdf-libs-development Feb 23, 2026
5 checks passed
@aaronlippold
aaronlippold deleted the fix/esm-json-imports-v2 branch February 23, 2026 23:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a Vite SSR compatibility issue by replacing ESM JSON import attributes with the createRequire pattern across the TypeScript packages. Vite SSR strips with { type: 'json' } import attributes during plugin analysis, breaking Node.js ESM imports. The solution uses createRequire(import.meta.url), which is the standard portable pattern for loading JSON in ESM environments.

Changes:

  • Replaced all import ... with { type: 'json' } with createRequire(import.meta.url) pattern across hdf-validators, hdf-mappings, and hdf-converters
  • Removed verbatimModuleSyntax from tsconfig.base.json to prevent TypeScript from emitting import attributes
  • Added ./package.json export to hdf-converters for self-reference imports

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tsconfig.base.json Removed verbatimModuleSyntax to prevent TS from emitting import attributes
hdf-validators/typescript/index.ts Migrated 9 schema imports from import attributes to createRequire pattern
hdf-mappings/src/scoutsuite/index.ts Migrated ScoutSuite mappings JSON import to createRequire
hdf-mappings/src/owasp/index.ts Migrated OWASP mappings JSON import to createRequire
hdf-mappings/src/nist/index.ts Migrated NIST descriptions JSON import to createRequire
hdf-mappings/src/nikto/index.ts Migrated Nikto mappings JSON import to createRequire
hdf-mappings/src/nessus/index.ts Migrated Nessus mappings JSON import to createRequire
hdf-mappings/src/cwe/index.ts Migrated CWE mappings JSON import to createRequire
hdf-mappings/src/cci/index.ts Migrated CCI mappings JSON imports (2 files) to createRequire
hdf-mappings/src/awsconfig/index.ts Migrated AWS Config mappings JSON import to createRequire
hdf-converters/package.json Added ./package.json export for self-reference capability
hdf-converters/converters/nessus-to-hdf/typescript/converter.ts Migrated package.json version import to createRequire with self-reference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

aaronlippold added a commit that referenced this pull request Feb 24, 2026
…er compatibility

Reverts the createRequire approach from #3 (563a1c6) which broke browser
bundles — `module.createRequire` is Node-only. Restores bare JSON imports
which work when consumers bundle via Vite noExternal.

Adds 46 compatibility tests to prevent regression.

Authored by: Aaron Lippold<lippold@gmail.com>
aaronlippold added a commit that referenced this pull request Mar 15, 2026
…ompatibility (#3)

Vite SSR strips `with { type: 'json' }` import attributes during transform
(RFC #18534), breaking any Nuxt/Vite consumer. Replace all JSON import
attributes with `createRequire(import.meta.url)` — the standard portable
ESM pattern that works in Node.js, Vite SSR, and all bundlers.

Changes:
- Remove verbatimModuleSyntax from tsconfig.base.json
- Convert 9 hdf-mappings JSON imports to createRequire
- Convert 9 hdf-validators schema imports to createRequire
- Convert hdf-converters nessus package.json import to createRequire
- Add ./package.json export to hdf-converters for self-reference import

All 434 tests pass. No import attributes remain in dist output.

Authored by: Aaron Lippold<lippold@gmail.com>

Signed-off-by: Aaron Lippold <lippold@gmail.com>
aaronlippold added a commit that referenced this pull request Mar 15, 2026
…er compatibility

Reverts the createRequire approach from #3 (53e4c19) which broke browser
bundles — `module.createRequire` is Node-only. Restores bare JSON imports
which work when consumers bundle via Vite noExternal.

Adds 46 compatibility tests to prevent regression.

Authored by: Aaron Lippold<lippold@gmail.com>
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