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

fix(js): do not default to commonjs type field in package.json #22819

Merged
merged 1 commit into from Apr 15, 2024

Conversation

Coly010
Copy link
Contributor

@Coly010 Coly010 commented Apr 15, 2024

Current Behavior

The @nx/js:library generator will default the packageJson.type field to commonjs in the following scenarios:

  • Rollup Bundler is used
  • No bundler is used

Rollup Behaviour

Rollup supports generating both ESM and CJS output files. The build target that is created even specifies that both formats should be used.
However, the @nx/rollup:rollup executor will restrict the output format based on the packageJson.type field.

Therefore, we're always forcing CJS. This can lead to further issues when the package is built and distributed to other repos.

The skipTypeField option is also not respected in commonjs output formats.

No Bundler Behaviour

When no bundler is specified for the library, we still add packageJson.type = commonjs.
This is unnecessarily restrictive and can lead to further behavioural issues.

It is safer to not set a type field and allow the user to specify this themselves based on their needs.

Expected Behavior

Do not default to commonjs for no bundler or with rollup.

Related Issue(s)

Fixes #19384

@Coly010 Coly010 requested a review from a team as a code owner April 15, 2024 10:48
@Coly010 Coly010 self-assigned this Apr 15, 2024
@Coly010 Coly010 requested a review from mandarini April 15, 2024 10:48
Copy link

vercel bot commented Apr 15, 2024

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

1 Ignored Deployment
Name Status Preview Updated (UTC)
nx-dev ⬜️ Ignored (Inspect) Visit Preview Apr 15, 2024 0:35am

@Coly010 Coly010 enabled auto-merge (squash) April 15, 2024 13:57
@Coly010 Coly010 merged commit 7dcd043 into nrwl:master Apr 15, 2024
6 checks passed
@Coly010 Coly010 deleted the js-cjs-default branch April 15, 2024 14:55
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 Apr 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants