-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
@nx/rollup built library errors when using new .cjs.mjs file #20009
Comments
@thomassimko Do you have a reprod for this? I have some questions:
I tried to reproduce this issue but could not. The weird thing is that the serving and building should be reading the |
Let me try to reproduce in a stripped down project for you. It was also my understanding that NextJS should be pulling the module instead of the import export. To answer your questions:
|
This happens because when there's only a default export, the CJS output exports it through e.g. given export class Foo {}
export default class Bar {} the output is // index.cjs.js
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
class Foo {
}
class Bar {
}
exports.Foo = Foo;
exports["default"] = Bar; But given export default class Bar {} the output is // index.cjs.js
'use strict';
class Bar {
}
module.exports = Bar; To make the const e = require('./index.cjs.js')
exports._default = e.default ?? e; @jaysoo would you like me to send a PR and/or provide a complete reproduction repo? |
I have created a sample NX repo where the component bundled has the output described by @alexgavrusev. Repo: https://github.com/davidlinhares/nx-rollup-multi-config (it says multi config but this has a single rollup config) |
another sample repo, description in README file |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Not stale. My coworkers are creating a new repo with this issue. |
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. |
Not stale. |
@jaysoo - any updates on this? We have several downstream products that are unable to utilize our product due to this. I'd like to know if there's a proposed timeline before we revert to a previous version of NX. |
@kajurek - your repo link above is not available. |
I have created a new repository that has this issue: https://github.com/thomassimko/nx-default-build-error You can see the issue by doing the following:
Please let me know if you have any other questions. This is a big issue for our team. |
Thanks for the repro, we'll take a look |
Thanks @jaysoo - please let us know if we can do anything else to help troubleshoot this. |
@jaysoo and I looked at the repo, it turns out the libraries have
Quick fixes would be removing
So the consuming app will resolve these libraries correclty. |
@xiongemi after looking at the rules that publint defines, the is a mention that
So that fix should probably also set |
@davidlinhares |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
After upgrading from NX v16 to NX v17, the build outputs for our React packages changed. Notably the exports section changed.
Now on a consuming application that is using NextJS and importing via
import { MODULE_NAME } from "PACKAGE"
, we are receiving errors that did not exist before.I am not an expert in ESM or CJS, but it seems very odd to me to change how this is exported across the versions.
Expected Behavior
I would expect my consuming application to be able to consume the library without errors.
GitHub Repo
No response
Steps to Reproduce
Nx Report
Failure Logs
Package Manager Version
No response
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: