-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Fail to require (in cjs) CSS modules from an npm package #13298
Comments
In the development stage, you can use vite plugin vite-plugin-cjs2esm to solve this problem. It provide esbuild plugin which can solve the commonjs import problem during esbuild pre-build stage. import { defineConfig } from 'vite'
import * as cjs2esm from 'vite-plugin-cjs2esm'
export default defineConfig({
plugins: [cjs2esm.vitePlugin()],
optimizeDeps: {
esbuildOptions: {
plugins: [cjs2esm.esbuildPlugin()]
}
}
}) |
@haijie-x thanks for the information. I tried to install this package and added the vite config file you provided. First, it works in the browser console, which is great! At the same time, I got another error in the terminal:
Is there anything I missed? Or do you have any idea how to make it works? Thanks. |
@Jinjiang Thanks for your feedback, please try the latest package version v1.0.6, a minor issue has just been fixed. |
I just tried it and it works. |
Cool. It works on 1.0.6 as you mentioned. Thanks so much. |
Hi, I'd like to reopen this issue since:
Thanks. |
This seems to be a regression from 4.2.0 caused by #12343. |
@sapphi-red thanks for pointing this out. I further found it works on v4.1.x 😅 |
Describe the bug
The background is I have some existing packages whose generated code is in CommonJS + CSS modules. E.g.
This file uses
require()
to load CSS Modules.In Vite, it fails to be loaded, however, an
import
works.Reproduction
https://github.com/Jinjiang/reproductions/tree/vite-cssmodules-20230523
Steps to reproduce
Then open browser, the console panel will show up:
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: