fix: replace ESM JSON import attributes with createRequire for Vite compatibility - #3
Merged
Merged
Conversation
…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>
Contributor
There was a problem hiding this comment.
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' }withcreateRequire(import.meta.url)pattern across hdf-validators, hdf-mappings, and hdf-converters - Removed
verbatimModuleSyntaxfrom tsconfig.base.json to prevent TypeScript from emitting import attributes - Added
./package.jsonexport 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>
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.
Summary
import ... with { type: 'json' }withcreateRequire(import.meta.url)across hdf-mappings, hdf-validators, and hdf-convertersverbatimModuleSyntaxfromtsconfig.base.json(was forcing TS to emit import attributes that Vite SSR strips)./package.jsonexport to hdf-converters for self-reference importProblem
Vite SSR strips
with { type: 'json' }import attributes during plugin analysis (RFC #18534), leaving bare JSON imports that Node.js rejects withModule 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
with { typein dist outputpnpm devworks in heimdall-enterprise consumer after submodule update