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

Astro: The requested module is a CommonJS module, ...may not support ... named exports with pnpm #355

Closed
lstephensca opened this issue Jul 25, 2024 · 4 comments · Fixed by #301

Comments

@lstephensca
Copy link

Not sure if this is qrcode.react specific or a configuration tweak that I need to make on my end, but If I load QRCodeSVG into an astro component (running in SSR using the node adapter and react), I get the following error with endless loading:

 <QRCodeSVG value={originalUrl} includeMargin={true} client:load />
Named export 'QRCodeSVG' not found. The requested module 'qrcode.react' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'qrcode.react';
const {QRCodeSVG} = pkg;

The only "fix" I have been able to come up with is by changing client:load to client:only="react" which is okay for the time being, but does introduce quite a flicker on page load.

Astro                    v4.12.2
Node                     v21.7.1
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/tailwind
                         @astrojs/react

I did double check and I am using the latest release of qrcode.react.

@zpao
Copy link
Owner

zpao commented Jul 25, 2024

Interesting… we do ship with support for both modern and commonjs modules and I thought that was set up correctly. I haven't seen any issues but perhaps people are falling back to the commonjs modules without realizing and just not hitting issues.

I've played around with Astro before so this should be easy enough to repro, but if you happen to have a chance to create the most minimal standalone example it would help :)

@lstephensca
Copy link
Author

lstephensca commented Jul 25, 2024

Sure thing! I set up a small astro example with node and react.

The first example works fine, save for some flickering (more noticeable while not in stackblitz) , if used with client:only="react". The second example uses client:load and generates the error regarding commonJS.

@zpao
Copy link
Owner

zpao commented Aug 3, 2024

Ok, looks like #301 fixes this. I'm not sure if I'm going to backport and do a 3.2.0 release, but I tagged that PR to make sure it gets included if I do.

I also found withastro/astro#3174 which helped me figure out the issue and may offer an interim solution for you.

Example was super helpful to diagnose and test this quickly, so thank you!

@zpao zpao closed this as completed Aug 3, 2024
@zpao zpao linked a pull request Aug 3, 2024 that will close this issue
@zpao
Copy link
Owner

zpao commented Sep 1, 2024

Hey, I did backport the fix for 3.2 (and shipped 4.0). Let me know if these don't work out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants