Skip to content

fix(json-imports): fix JSON import compatibility across Node versions #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

harshrox
Copy link

@harshrox harshrox commented Apr 2, 2025

Issue

The assert keyword used in JSON imports does not work with Node.js v22, causing an import error as shown in the image below.
Screenshot from 2025-04-02 20-53-33

We could have used the "with" statement instead of assert, which works in Node.js v22, but it is not supported in older Node.js versions. This would have led to compatibility issues across different versions.

Fix

Replaced all assert { type: "json" } imports with fs.readFileSync()-based JSON parsing. This method ensures compatibility with all Node.js versions, as it relies on fs.readFileSync() instead of import assertions.

Screenshot after the fix:
Screenshot from 2025-04-02 20-54-55

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