-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Unable to load @react-aria/textfield as ESM module #2881
Comments
The last line does have the export defined... so not sure what would be happening. export {$7811e7c771d6e497$export$712718f7aec83d5 as useTextField, $7f9aed3807b71324$export$4f384c9210e583c3 as useFormattedTextField}; |
Similar issue moving from |
Had a quick skim over your history for |
Could someone provide reproduction steps for this? |
Possibly related, I'm having issues using these components in NextJS SSR while native ESM is enabled due to a missing |
Ok I figured it out, this particular problem is an issue with the CJS export. Node.js does attempt to load ESM exported by this library unless explicitly asked to (e.g. compare these two and scroll to the bottom: Node.js has a somewhat flaky heuristic for providing named exports for CJS: https://nodejs.org/api/esm.html#commonjs-namespaces The important line is here
Parcel 2 changed from assigning to To reproduce, just run a script ending in import { mergeProps } from '@react-aria/utils'; // v3.12.0 Then downgrade utils to 3.11.0 and watch the error go away |
Bump. Any news on this? |
@devongovett any way I can help on this? I'm blocked from updating any dependencies until this is resolved. I see two options:
I'm not sure if I have the bandwidth to look at option 2. since I think it would involve proposing an implementing a solution to parcel-bundler/parcel#4155. I could probably could come up with a workaround using the release scripts in the meantime. |
What is causing a CJS module to be loaded as ESM in the first place? |
CJS isn't loading as ESM, Node is just statically analyzing it for named exports. This analysis happens when you request a module like the following from an ESM context (e.g. a file ending in .mjs)
And the reason Node is even looking at the CJS file in the first place is because its ESM loader will only look for it at Footnotes
|
I got that, but where is this ESM import of a React Aria package running in node? You mentioned Next.js but I thought they used CJS. |
NextJS uses ESM by default as of version 12! |
Hmm, I have a test project using next 12.1.6 and it seems to work fine... https://github.com/devongovett/rsp-next Any other configuration? |
I have this issue with viteJS in SSR mode which also use ESM by default in V3 |
You could use a CJS require in the meantime, or transpile your code to CJS. Node ESM has never really been supported by React Aria. It may have worked by accident sometimes due to node's flaky interop, but we don't currently test against it. If we wanted to support it, I guess using an |
We're blocked on this as well. Is there a workaround anyone as found? Currently if I rewrote the output to use normal |
I've merged this branch, we're going to have it in nightlies for a while to make sure we haven't broken anything. Our targeted release date for this is January. Please try it out on the nightlies which publish at 2am PDT. |
Unfortunately, we had to revert this for now. It broke webpack 4, which still has more downloads per week than webpack 5. See #3839 for details. We may be able to regroup in the new year, but so far we haven't found a solution that works across all tools. |
Update: I think I got a new approach working in #4038. We will do some more testing to be sure. |
🐛 Bug Report
Starting with version 3.5.1, the contents of
@react-aria/textfield/dist/module.js
seems to have become garbled. The file at version 3.5.0 looks good and can be correctly loaded as an ESM module.🤔 Expected Behavior
The file to be loaded correctly, for example, by jest.
😯 Current Behavior
The module is not understood by node:
💁 Possible Solution
🔦 Context
Trying to run unit tests against a component that depends on
@react-aria/textfield
.💻 Code Sample
🌍 Your Environment
🧢 Your Company/Team
🕷 Tracking Issue (optional)
The text was updated successfully, but these errors were encountered: