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 v4 SSR - The requested module '@material-tailwind/react' is a CommonJS module #10644

Closed
1 task
r1y4h opened this issue Apr 2, 2024 · 1 comment · Fixed by #10654
Closed
1 task

Astro v4 SSR - The requested module '@material-tailwind/react' is a CommonJS module #10644

r1y4h opened this issue Apr 2, 2024 · 1 comment · Fixed by #10654
Labels
- P2: nice to have Not breaking anything but nice to have (priority) pkg: react Related to React (scope)

Comments

@r1y4h
Copy link

r1y4h commented Apr 2, 2024

Astro Info

Astro                    v4.5.13
Node                     v20.11.0
System                   Windows (x64)
Package Manager          yarn
Output                   static
Adapter                  none
Integrations             @astrojs/react
                         @astrojs/tailwind

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

In Astro v3, importing components from '@material-tailwind/react' works fine for both SSR and CSR

import { Button } from '@material-tailwind/react';

Then on my Astro page:

<Menu client:only="react" />
<Menu />

In Astro v4, the above works fine for client side rendering only.
But if you try this in Astro v4 SSR, Vite will throw an error:

[vite] Named export 'Button' not found. The requested module '@material-tailwind/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 '@material-tailwind/react';
const {Button} = pkg;

The error points to '@material-tailwind/react' being a CommonJS module. I read that Vite v5 requires ESM after v4, but why does it work with CSR?

For now I added this in my Astro config as a workaround:

vite: {
    legacy: {
      proxySsrExternalModules: true
    }
  }

What's the expected result?

import { Button } from '@material-tailwind/react';

Should work for both SSR and CSR

Link to Minimal Reproducible Example

CodeSandbox Link

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Apr 2, 2024
@matthewp matthewp added - P2: nice to have Not breaking anything but nice to have (priority) pkg: react Related to React (scope) and removed needs triage Issue needs to be triaged labels Apr 2, 2024
@r1y4h
Copy link
Author

r1y4h commented Apr 3, 2024

@matthewp thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) pkg: react Related to React (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants