Skip to content

"Styles were unable to be assigned to a file" error in Qwik project if used in root route #1625

@EatChangmyeong

Description

@EatChangmyeong

Describe the bug

vanilla-extract fails to extract styles if all of the following conditions are met:

  • vanilla-extract is used with Qwik
  • dev server has just started with npm run dev or npm start
    • The error disappears with npm run preview or when style is added while dev server is already running
  • the route / (i.e. /src/routes/index.tsx or /src/routes/layout.tsx) references vanilla-extract classes in any way
    • The error shows immediately after dev server is ready, even without any browser tabs to trigger it

This bug also affects styled-vanilla-extract, which is how I first discovered it.

The reproduction was created with the following steps:

  1. npm create qwik@latest
  2. select Empty App (Qwik City + Qwik)
  3. npm i @vanilla-extract/css @vanilla-extract/vite-plugin
  4. add vanillaExtractPlugin to vite.config.ts
  5. add a minimal style in /src/routes/style.css.ts and use it in /src/routes/index.tsx

Reproduction

https://github.com/EatChangmyeong/vanilla-extract-qwik-repro

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
    Memory: 1.39 GB / 7.86 GB
  Binaries:
    Node: 22.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 10.12.4 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.112)
    Internet Explorer: 11.0.26100.1882
  npmPackages:
    @vanilla-extract/css: ^1.17.4 => 1.17.4
    @vanilla-extract/vite-plugin: ^5.1.0 => 5.1.0
    vite: 5.3.5 => 5.3.5

Used Package Manager

npm

Logs

PS C:\vanilla-extract-qwik-repro> npm run dev                                                 

> dev
> vite --mode ssr

using deprecated parameters for the initialization function; pass a single object instead
(!) Could not auto-determine entry point from rollupOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency pre-bundling.

  VITE v5.3.5  ready in 3033 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
오전 3:27:37 [vite] Error when evaluating SSR module /src/routes/style.css.ts:
|- 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 Object.getFileScope (C:\vanilla-extract-qwik-repro\node_modules\@vanilla-extract\css\fileScope\dist\vanilla-extract-css-fileScope.cjs.dev.js:35:11)
    at generateIdentifier (C:\vanilla-extract-qwik-repro\node_modules\@vanilla-extract\css\dist\vanilla-extract-css.cjs.dev.js:155:49)
    at Module.style (C:\vanilla-extract-qwik-repro\node_modules\@vanilla-extract\css\dist\vanilla-extract-css.cjs.dev.js:415:19)
    at eval (C:/vanilla-extract-qwik-repro/src/routes/style.css.ts:5:35)
    at async instantiateModule (file:///C:/vanilla-extract-qwik-repro/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:52650:5)

오전 3:27:37 [vite] Error when evaluating SSR module C:/vanilla-extract-qwik-repro/src/routes/index.tsx:
|- 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 Object.getFileScope (C:\vanilla-extract-qwik-repro\node_modules\@vanilla-extract\css\fileScope\dist\vanilla-extract-css-fileScope.cjs.dev.js:35:11)
    at generateIdentifier (C:\vanilla-extract-qwik-repro\node_modules\@vanilla-extract\css\dist\vanilla-extract-css.cjs.dev.js:155:49)
    at Module.style (C:\vanilla-extract-qwik-repro\node_modules\@vanilla-extract\css\dist\vanilla-extract-css.cjs.dev.js:415:19)
    at eval (C:/vanilla-extract-qwik-repro/src/routes/style.css.ts:5:35)
    at async instantiateModule (file:///C:/vanilla-extract-qwik-repro/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:52650:5)


  🚧 Please note that development mode is slower than production.

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions