Vitest error when import svg #5271
Replies: 5 comments 9 replies
-
I'm not familiar with bit, but normally the files in To force Vitest to treat |
Beta Was this translation helpful? Give feedback.
-
I am having the exact same issue. Did you manage to solve it? |
Beta Was this translation helpful? Give feedback.
-
I got it to work using these props for svgr
|
Beta Was this translation helpful? Give feedback.
-
If you having this issue with vue3 use this plugin (anything else didn’t work for me) |
Beta Was this translation helpful? Give feedback.
-
@toomanychrises I had your exact issue. A component library we were using was using require. And although things would work in dev, it would fail in vitest. And after finding your question, it finally led me to this answer. const require = createRequire(import.meta.url)
require.extensions['.svg'] = (_, filename) => `module.exports = "${filename}"``` |
Beta Was this translation helpful? Give feedback.
-
I'm getting a similar error to #1766 where it seems like it's only happening when import a package that is a component (in bit) that's compiled to commonjs. The error doesn't happen when this identical component is local instead of being a package.
Sorry if this is a rookie question, but I need to know what to do, whether it's a matter of changing how this component is packaged/build, or how we are importing it into the vite repo, or how I'm configuring vitest to use it... this error does not occur when running the app, only in vitest
svg-list.js (in component)
vite.config.js:
which obviously leads to an SVG asset that other DS components use. Any workaround for vitest on this? I've tried a few
test.alias
that points it to a fileMock that exports aspan
andplugins
replacements, but I'm not sure I have to correct syntax. Any advice?Beta Was this translation helpful? Give feedback.
All reactions