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

Reserved JS keywords are not allowed as CSS modules class names #14050

Open
7 tasks done
Maxou44 opened this issue Aug 9, 2023 · 4 comments · May be fixed by #16018
Open
7 tasks done

Reserved JS keywords are not allowed as CSS modules class names #14050

Maxou44 opened this issue Aug 9, 2023 · 4 comments · May be fixed by #16018
Labels
bug: upstream Bug in a dependency of Vite enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@Maxou44
Copy link

Maxou44 commented Aug 9, 2023

Describe the bug

When using CSS modules and importing to obtain computed class names, classes named using a JS reserved keywords are not available and return undefined.

There is no console warning or information in the documentation about that, and this test works on Webpack and Parcel.

As the following code is valid in JS, I don't think it should be a problem to support it:

const obj = {
  for : 'hello',
  while: 'world',
};
console.log(obj.for, obj.while);

Reproduction

https://stackblitz.com/edit/vitejs-vite-qmdhmt?file=main.js

Steps to reproduce

No response

System Info

Vite v4.4.9

Used Package Manager

npm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented Aug 9, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@sapphi-red sapphi-red added enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) labels Aug 9, 2023
@sapphi-red
Copy link
Member

sapphi-red commented Aug 9, 2023

This is not supported because export const for = '' is not valid. We'll need rollup/plugins#1437 to be implemented.

related: #11359

You can import the default import instead for a workaround.

import style from './style.module.css';

@bluwy bluwy added the bug: upstream Bug in a dependency of Vite label Aug 23, 2023
@privatenumber privatenumber linked a pull request Feb 23, 2024 that will close this issue
12 tasks
@privatenumber
Copy link
Sponsor Contributor

privatenumber commented Feb 29, 2024

@Maxou44

I've implemented a fix via https://github.com/privatenumber/vite-css-modules (which is getting integrated into Vite core via #16018).

Would you mind testing it out to see if it resolves your issue?

EDIT: Confirmed working via privatenumber/vite-css-modules@9fdfa5b

@Maxou44
Copy link
Author

Maxou44 commented Mar 12, 2024

@privatenumber Tested and it works, thanks for the fix 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: upstream Bug in a dependency of Vite enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants