Skip to content
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

Support importing as ESM in Node #51

Closed
wants to merge 1 commit into from
Closed

Conversation

MattiasBuelens
Copy link
Owner

@MattiasBuelens MattiasBuelens commented May 31, 2020

This uses conditional exports to define the CommonJS and ES module paths for each variant. This enables modern Node versions to load the .mjs files, instead of the CommonJS .js builds.

As explained in the documentation, this will prevent consumers from using anything that is not defined by exports, so they will no longer be to do e.g. require("web-streams-polyfill/dist/polyfill.js"). This is likely a breaking change.

Moreover, consumers may already be using import streams from "web-streams-polyfill" with modern Node, which would give them the CommonJS module as a default export. This will also break, since the default export will be replaced by named exports. Consumers will need to change their code to either import { ReadableStream } ... or import * as streams ... instead.

To do:

  • Add tests for loading the different variants as CommonJS or ES modules.

@MattiasBuelens MattiasBuelens self-assigned this May 31, 2020
@MattiasBuelens MattiasBuelens added this to the v3.0.0 milestone May 31, 2020
@MattiasBuelens
Copy link
Owner Author

This probably needs to wait for microsoft/TypeScript#33079, since the current version of TypeScript won't be able to find the correct type definitions for each subpath export.

@MattiasBuelens MattiasBuelens modified the milestones: v3.0.0, Future Jul 20, 2020
@MattiasBuelens
Copy link
Owner Author

Superseded by #83.

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

Successfully merging this pull request may close these issues.

None yet

1 participant