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

Vite version 2.9.2 and beyond don't honor external package CSS/Sass module inclusion in output bundle #8461

Closed
7 tasks done
reintroducing opened this issue Jun 3, 2022 · 6 comments · Fixed by #8936
Closed
7 tasks done
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release

Comments

@reintroducing
Copy link

Describe the bug

This bug is evident in any version of Vite after v2.9.1.

When you have an external npm module (in this case, @reintroducing/my-package) that loads its own Sass file as a CSS module, using that file in dev mode works perfectly fine and you can see the CSS associated with the external module reflected in your dev server. But if you build and preview that code, you will see that the CSS for the external module is there but the class is not applied to the element and there is no mention of the module name in the output JS bundle.

Steps to Reproduce Working Version

  1. Clone repo and npm i.
  2. Run npm run dev. Observe the Test button and its blue background.
  3. Inspect the blue button and in dev tools verify that it has the class Button-module-root as expected.
  4. Stop the dev server and run npm run preview. Observe the Test button and its blue background.
  5. Inspect the blue button and in dev tools verify that it has the class Button-module-root as expected.
  6. In the generated dist, open assets/index[hash].js and search for Button-module-root to verify it is there.
  7. In the generated dist, open assets/index[hash].css and search for Button-module-root to verify it is there.

Steps to Reproduce Non-Working Version

  1. Upgrade Vite to any version after 2.9.1 (2.9.2+, although 2.9.2 is when this bug starts showing up).
  2. Run npm i.
  3. Run npm run dev. Observe the Test button and its blue background.
  4. Inspect the blue button and in dev tools verify that it has the class Button-module-root as expected.
  5. Stop the dev server and run npm run preview. Observe the Test button and the missing blue background.
  6. Inspect the button and in dev tools verify that it no longer has the class Button-module-root as expected.
  7. In the generated dist, open assets/index[hash].js and search for Button-module-root to verify it is no longer there.
  8. In the generated dist, open assets/index[hash].css and search for Button-module-root to verify it is there.

The code for the external Button is super simple and can be found here.

Reproduction

https://github.com/reintroducing/vite-bug

System Info

System:
    OS: macOS 12.3.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 80.34 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
  Browsers:
    Chrome: 102.0.5005.61
    Firefox: 97.0.1
    Safari: 15.4
  npmPackages:
    @vitejs/plugin-react: ^1.3.0 => 1.3.2
    vite: 2.9.1 => 2.9.1

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red sapphi-red added feat: css p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release and removed pending triage labels Jun 4, 2022
@sapphi-red
Copy link
Member

This is affected by #7591 and it is fixed by #8278.
Closing as I confirmed upgrading to 3.0.0-alpha.2 fixed this.

@reintroducing
Copy link
Author

reintroducing commented Jun 4, 2022

@sapphi-red can you expand on this? I just tried 3.0.0-alpha.2 in my reproduction repo (npm run dev) and it doesn't even load, getting an error in console and blank white screen:
Screen Shot 2022-06-04 at 8 47 59 AM

it's not until version 3.0.0-alpha.4 that it actually loads up in dev correctly again. that being said, if you run npm run preview under 3.0.0-alpha.4, it works as expected in the output as well. However, starting with version 3.0.0-alpha.5, preview is throwing a new error and a blank white screen:
Screen Shot 2022-06-04 at 8 51 11 AM

@sapphi-red
Copy link
Member

sapphi-red commented Jun 4, 2022

About 3.0.0-alpha.2, that was a bug which is fixed after 3.0.0-alpha.4.

About that "require is not defined" error, it seems there is a different bug. A similar error happens even after updating plugin-react to 2.0.0-alpha.2.

@reintroducing
Copy link
Author

@sapphi-red got it, so this is a known issue and not one with my code then. hopefully it can get sorted in the next alpha release. appreciate the quick responses to this issue. for the time being i'll downgrade to vite 2.9.1 and eagerly await the 3.0.0 release (which will hopefully fix all the bugs :)

@sapphi-red
Copy link
Member

Reopening as #8278 and #8471 was reverted. See #8896 and #8874 for details.
I'll create a PR for v3 later to fix this.

@sapphi-red sapphi-red reopened this Jul 3, 2022
@vitejs vitejs unlocked this conversation Jul 3, 2022
pull bot pushed a commit to jango-blockchained/vite that referenced this issue Jul 3, 2022
@sapphi-red
Copy link
Member

related: #6179

nvh95 pushed a commit to nvh95/vite that referenced this issue Jul 3, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority) regression The issue only appears after a new release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants