creativetimofficial / material-tailwind

@material-tailwind is an easy-to-use components library for Tailwind CSS and Material Design.
https://material-tailwind.com/
MIT License
3.43k stars 302 forks source link

Support for Astro v4 #661

Closed r1y4h closed 1 month ago

r1y4h commented 2 months ago

In Astro v3, the documented way of importing works fine for both server side and client side rendering:

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

In Astro v4, the above works fine for client side rendering.

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;

We should be able to import material-tailwind components the same way for both SSR and CSR, so we can fully take advantage of Astro Islands concept.

r1y4h commented 2 months ago

It seems Astro v4 SSR only supports ESM modules while material-tailwind still uses CommonJS. Thus the problem. Will you convert material-tailwind to use ESM instead? @sajadevo

r1y4h commented 2 months ago

Reported this to Astro, and they would fix this on their end: https://github.com/withastro/astro/pull/10654