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

Add support for Node ESM #4038

Merged
merged 20 commits into from
Feb 14, 2023
Merged

Add support for Node ESM #4038

merged 20 commits into from
Feb 14, 2023

Conversation

devongovett
Copy link
Member

Closes #2881

This re-adds support for Node ESM after it was reverted in #3839 due to breaking webpack 4. Now we use a new strategy which distributes three files for each module:

  • dist/main.js – the CommonJS version in the "main" field, used by node when required, jest, etc.
  • dist/module.js – the legacy ESM version in the "module" field, used by webpack 4 and other tools that don't support package.json exports. This is needed because .mjs doesn't work properly in webpack 4.
  • dist/import.mjs – the modern ESM version in the "exports.import" field, used by Node and other tools supporting exports. This is the exact same as dist/module.js but with the .mjs extension for Node.

I also tried using "type": "module" in package.json to avoid the third entry point, but this broke other things since it applies to all .js files and not just the dist directory.

The icons now distribute two versions each:

  • IconName.js – the CommonJS version
  • IconName.module.mjs – the ESM version. This is specially not named IconName.mjs so that webpack 4 does not try to resolve it and then fail to resolve the imports. Only tools that support package.json exports will resolve this file.

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert circle ci config.yml changes for approval

packages/@react-spectrum/alert/package.json Show resolved Hide resolved
plop-templates/@react-aria/package.json.hbs Outdated Show resolved Hide resolved
plop-templates/@react-aria/package.json.hbs Outdated Show resolved Hide resolved
scripts/cleanIcons.js Outdated Show resolved Hide resolved
scripts/esm-support/supportESM.js Outdated Show resolved Hide resolved
scripts/verdaccio.sh Outdated Show resolved Hide resolved
@rspbot
Copy link

rspbot commented Feb 14, 2023

@rspbot
Copy link

rspbot commented Feb 14, 2023

@rspbot
Copy link

rspbot commented Feb 14, 2023

## API Changes

unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }

Copy link
Member

@LFDanLu LFDanLu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, tested the webpack 4 app in the earlier commit, will retest on main when merged.

@devongovett devongovett merged commit f5c005b into main Feb 14, 2023
@devongovett devongovett deleted the support-ESM-again branch February 14, 2023 19:21
@vstreame
Copy link

🎉 congrats @devongovett and @snowystinger !

@abdulhdr1
Copy link

as the issue is already closed and merged, is there a patch release estimate?
it would fix some problems on this next.js issue

@hastebrot
Copy link

@abdulhdr1 if it helps, there are nightly releases of react-aria, react-spectrum, and @react-types packages, e.g. react-aria@3.22.1-nightly.3714 at https://www.npmjs.com/package/react-aria?activeTab=versions.

@beamery-tomht
Copy link
Contributor

When will this reach packages like @react-aria/utils ?

@dannify
Copy link
Member

dannify commented Feb 23, 2023

This will be released in the next week. Hold tight!

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.

Unable to load @react-aria/textfield as ESM module
9 participants