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 plugin is not extracting the styles in CSS file when used in module federation setup #1506

Closed
2 tasks done
smitev opened this issue Nov 20, 2024 · 3 comments · Fixed by #1537
Closed
2 tasks done
Labels
upstream issue Issue caused by a required upstream dependency vite Issue related to vite

Comments

@smitev
Copy link

smitev commented Nov 20, 2024

Describe the bug

I have a module federation setup with Vite using vite-plugin-federation. Also I am using vite-tsconfig-paths. When I try to build the apps, it doesn't compile/extract the styles in separate CSS file, instead it keeps them in JS files and when I run/preview the built app, I get this error: Uncaught Error: Styles were unable to be assigned to a file.

I noticed when I don't use vite-tsconfig-paths for the imports, the build output is correct.
I also tried to set vanillaExtractPlugin({ unstable_mode: 'transform' }) and that one also gives the correct build output.

Reproduction

https://github.com/smitev/vanilla-extract-vite-module-federation

System Info

System:
    OS: macOS 14.7.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 301.97 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.11.0 - /opt/homebrew/opt/node@22/bin/node
    Yarn: 4.5.1 - /opt/homebrew/opt/node@22/bin/yarn
    npm: 10.9.0 - /opt/homebrew/opt/node@22/bin/npm
  Browsers:
    Chrome: 131.0.6778.86
    Edge: 131.0.2903.51
    Safari: 18.1

Used Package Manager

yarn

Logs

Uncaught Error: Styles were unable to be assigned to a file. This is generally caused by one of the following:

- You may have created styles outside of a '.css.ts' context
- You may have incorrect configuration. See https://vanilla-extract.style/documentation/getting-started
    at getFileScope (__federation_expose_RemoteApp-GIBzU0Fx.js:3194:11)
    at generateIdentifier (__federation_expose_RemoteApp-GIBzU0Fx.js:4980:7)
    at style (__federation_expose_RemoteApp-GIBzU0Fx.js:5047:19)
    at __federation_expose_RemoteApp-GIBzU0Fx.js:5057:19

Validations

@askoufis askoufis added vite Issue related to vite upstream issue Issue caused by a required upstream dependency and removed pending triage labels Dec 16, 2024
@askoufis
Copy link
Contributor

I think both vite-tsconfig-paths and unstable_mode: 'transform' are red herrings. I've observed non-deterministic build output, regardless of whether or not the tsconfigPaths plugins is used.

Below is two builds performed one after another. One emits a CSS file, but the other doesn't. This can occur with or without the tsconfigPaths plugin. The CSS file is only occasionally generated. Usually it isn't generated.

image

Additionally, unstable_mode: 'transform' doesn't emit CSS files, so it "works", but that's because it's just loading the CSS at runtime via our runtime adapter, which is injected because VE is ending up bundled in the built module. This clearly isn't desirable.

I'm not sure what's causing this non-deterministic build, but for now I'm going to label this as an upstream issue and suggest you make an issue in vite-plugin-federation. If the maintainers of vite-plugin-federation can identify an issue within Vanilla Extract then we can proceed from there.

@smitev
Copy link
Author

smitev commented Jan 17, 2025

@askoufis thanks for checking it up.

I created issue on vite-plugin-federation for it.
originjs/vite-plugin-federation#666

@askoufis
Copy link
Contributor

askoufis commented Jan 30, 2025

@smitev The fix for this was released in @vanilla-extract/[email protected]. It was likely related to the federation vite plugin being passed through to the Vanilla Extract compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream issue Issue caused by a required upstream dependency vite Issue related to vite
Projects
None yet
2 participants