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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit a9efb44. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 6 targets
Sent with 💌 from NxCloud. |
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. |
Current Behavior
The
@nx/js:library
generator will default thepackageJson.type
field tocommonjs
in the following scenarios: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 thepackageJson.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 incommonjs
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