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

feat(web): add support for Node ESM when used to package SSR-ready library #10349

Merged
merged 1 commit into from May 18, 2022

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented May 17, 2022

This PR changes the output of libraries built with @nrwl/web:rollup so both ESM and CJS will work in Node.

Current Behavior

Building with both CJS and ESM results in failed import when trying to import ESM. This error is due to missing type: "module" entry in package.json.

Expected Behavior

Both ESM and CJS import/require works.

Changes

  • New type: module field for output package.json file.
  • New exports field for output package.json file
  • Set default format to ESM only (CJS isn't needed on the web, but could be used for Node if desired)
  • Migration to set format to ESM + CJS if not previously set (so previous UMD users can use CJS) -- can always override it if needed

@nx-cloud
Copy link

nx-cloud bot commented May 17, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit f7fac7c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 12 targets

Sent with 💌 from NxCloud.

@vercel
Copy link

vercel bot commented May 17, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
nx-dev ✅ Ready (Inspect) Visit Preview May 18, 2022 at 0:56AM (UTC)

Copy link
Contributor

@nartc nartc left a comment

Choose a reason for hiding this comment

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

Suggestions and question

@ajwootto
Copy link
Contributor

ajwootto commented Sep 21, 2022

@jaysoo how come the default was changed here without a migration? isn't this a backwards-incompatible change? Removing the commonjs output breaks any tests using Jest since it still uses CommonJS

edit: to clarify, I was publishing a package to npm using the output from this executor. When the package is published as ESM-only, it still works in a web application which uses a bundler like webpack, but can not be required in a standard Jest test setup (which doesn't touch the node_modules/ directory and also does not support loading ESM modules except in "experimental" mode)

@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants