Skip to content

migrate to ESModules #348

Closed
Closed

Description

@BIG293

The library at the moment is using commonJS modules with require to imports other modules. You should migrate to modern ESModules to be compliant with modern bundling systems that applies three shaking techniques.

Activity

  1. CarlosNZ commented on Jun 23, 2024

    @CarlosNZ

    In the same vein, it would be good to separate the parse and stringify functions, so if you're only using one of them, you can tree-shake the other out of our builds.

    (I recently removed stringify and am only using parse in my project -- I'd hoped that would reduce the bundle size somewhat, but it doesn't)

  2. jordanbtucker commented on Jun 23, 2024

    @jordanbtucker
    Member

    Thanks for the suggestion. JSON5 v3 is being written in TypeScript, and it will be ESM first (with a CommonJS bundle for backward compatibility). parse and stringify are already in different files right now, and that will be the same in v3.

  3. DraTeots commented on Jul 26, 2024

    @DraTeots

    Hello! Couldn't find the JSON5 v3 in typescript. Could you point out if one can use it?

  4. jackpunt commented on Feb 24, 2025

    @jackpunt

    I see source for a V3, but it seems to be from 3 years ago?
    And is not in typescript?

    Can you say more about how we can install a typescript or ESM version of JSON5?
    (or even convince typescript/vscode to use the parse.d.ts that comes with the package?)

    the cjs version is 'working', but webpack/angular keeps barking:
    "CommonJS or AMD dependencies can cause optimization bailouts."

  5. bybraveHQ commented on Jul 5, 2026

    @bybraveHQ
    Collaborator

    Done in the maintained fork @bybrave/json5: the sources are now ES modules with an exports map (the CJS entry is generated from them for the require condition). This also fixes #240 — import { parse, stringify } works and the import/require shapes match. Build moved from rollup+buble to a single esbuild step; zero runtime deps. npm i @bybrave/json5.

  6. aseemk commented on Jul 21, 2026

    @aseemk
    Member

    @bybraveHQ: I'm just seeing your fork for the first time. Love to see it! Would you be interested in becoming a maintainer here and bringing your changes back here? Or are you happy and would prefer to keep to your own fork instead? No pressure either way, and thank you for your work.

  7. fisker commented on Sep 17, 2026

    @fisker

    Hello @aseemk, I'm on the Prettier core team. As you can see from the links above, we already switched to bybraveHQ's fork. I'm willing to help with the migration if bybraveHQ is busy.

  8. bybraveHQ commented on Sep 17, 2026

    @bybraveHQ
    Collaborator

    @aseemk Sorry for the slow reply, and thank you — yes, I'd be glad to become a maintainer and bring the changes back here.

    I've opened #370 with the packaging part (fixes #240 and this issue): ES module sources, an exports map so import {parse, stringify} and require resolve to the same shape, a single esbuild build step, bundled types, node:test instead of tap, and GitHub Actions CI. The behavior changes from the fork (opt-in BigInt parsing from #292 and lone-surrogate escaping from #192) are deliberately not included; I'll send them as separate PRs once this lands.

    @fisker Thanks for the offer — a review from the Prettier side would be very welcome, since you're already running this in production. Once it ships as json5 v3 I'll deprecate @bybrave/json5 in favor of it.

  9. fisker commented on Sep 17, 2026

    @fisker

    Great!

  10. bybraveHQ commented on Oct 13, 2026

    @bybraveHQ
    Collaborator

    @fisker Quick status check on #370: all review threads are addressed, the PR is mergeable, but CI still hasn't run because the workflow needs a maintainer's approval, and there's been no response from @aseemk since my ping on Sept 23. Looking at the repo, #371 is also waiting on him.

    Since you offered to help with the migration — do you have a way to reach Aseem directly, or any suggestion on how to move this forward? I'm happy to keep the PR up to date and split out the follow-ups (BigInt, lone surrogates) as separate PRs once this one lands.

    Thanks again for the reviews.

  11. fisker commented on Oct 13, 2026

    @fisker

    do you have a way to reach Aseem directly

    Sorry, I don't.

    any suggestion on how to move this forward?

    Guess we'll have to wait. Hope we can get the repo and NPM access once @aseemk come back, so we don't have to wait for him again.

  12. jordanbtucker commented on Oct 14, 2026

    @jordanbtucker
    Member

    Hey, all. Sorry for the lack of response on this repo. I'll be connecting with @aseemk to discuss future maintainers for JSON5. I don't want JSON5 to continue to languish under my care because I haven't had the time to focus on it.

    In the meantime, I'm going to go through the existing issues (starting with this one) and prioritize what can be updated for v2 and work on a plan for v3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions