Skip to content

The benefits of supporting JSON modules named exports would outweigh the downsides #22

@zbrogz

Description

@zbrogz

Summary

Respectfully, I believe not supporting named exports with JSON modules was the wrong decision. Importing JSON modules with named exports is indeed more ergonomic and lends itself to tree shaking.

This was a useful feature in Webpack, but is in the process of being removed due to this proposal. See webpack/webpack#9246

Response to reasons given

From: https://github.com/tc39/proposal-json-modules#why-dont-json-modules-support-named-exports

They are not fully general: not all JSON documents are objects, and not all object property keys are JavaScript identifiers that can be bound as named imports.

Sure, but that doesn't mean it wouldn't be useful. I would prefer to have the feature available even if it has limitations.

It makes sense to think of a JSON document as conceptually whatwg/html#4315 (comment) rather than several things that happen to be side-by-side in a file.

I think it can also make sense to think of a JSON document in terms of different importable fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions