Skip to content

@stratakit/mui and @stratakit/icons don't play well with vitest #1567

Description

@jasonjwichert

Describe the bug

@stratakit/mui packaging issue causing downstream bundler/test failures

Issue — dist/Icon.js uses hardcoded static .svg imports

dist/Icon.js contains static imports of .svg files:

import svgArrowDown from "@stratakit/icons/arrow-down.svg";
import svgCheckmark from "@stratakit/icons/checkmark.svg";
// ...etc

Any environment that loads the published JS through Node's native module loader (e.g. Vitest by default) fails, because Node has no loader for .svg: TypeError: Unknown file extension ".svg"

Workaround that we use: force the package through the bundler's asset pipeline (in Vitest config, test.server.deps.inline: [/@stratakit\/(mui|icons)/]).

Additional issue on Windows only:

Vite shipped a security fix in 8.0.16 #22572 (GHSA-fx2h-pf6j-xcff) that rejects any file path containing ~ on Windows.

The workaround above for Vitest (deps.inline) routes every @stratakit/mui module through Vite's per-file pipeline, which now rejects dist/DEV/~createTheme.js and all other files that start with ~. So once the package is inlined, loading these files on Windows fails with:

Error: Cannot find module '.../dist/DEV/~createTheme.js'

This is ~ issue is Windows-only, with the workaround being disabling server.fs.strict in vite config for vitest.

Note: this ~ issue only comes up because the .svg issue forces inlining in the first place.

Summary of workarounds required:

  1. deps.inline → to resolve the .svg imports, which then
  2. (Windows only) requires server.fs.strict: false (scoped to tests) → to get past the ~ filename rejection that setup monorepo #1 exposes.

Steps to reproduce

  1. Consume @stratakit/mui@0.4.1 in a Vite 8.0.16 + Vitest 4.1.9 project on Windows.
  2. Render any component that imports from @stratakit/mui.
  3. Without deps.inlineUnknown file extension ".svg".
  4. With deps.inline but fs.strict enabled → Cannot find module '.../~createTheme.js'.

Expected behavior

Would be great to run Vitest without multiple config workarounds, or at the least we should document these workarounds on https://stratakit.bentley.com/docs/getting-started/develop as Vitest is a very common tool.

Link to minimal reproduction

stackblitz is currently broken for vite 8.x, will post when fixed, see stackblitz/webcontainer-core#2104

Environment and versions

  • @stratakit/mui@0.4.1 (which pulls @stratakit/icons)
  • vite@8.0.16
  • vitest 4.1.9
  • pnpm
  • Windows (for ~ filename issue)

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions