You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot use import subpaths in css url() paths #16155
I don't know whether this should work or not, but it did when using resolve config previously, it worked fine. Now that I've converted over to using subpath imports, url() calls in my css files do not resolve. I tried using Vite 5.0.x and 5.2.0-beta.0, and neither one worked.
Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
Defining import map in package.json does not work currently.
Manually edit config.resolve.alias if you want to map @assets/* to ./src/assets/* in CSS. (#assets/* would not work because it was regarded as a hashtag)
vue implemented this for attributes with their own checks by what I think is seeing if the path resolves to a file then use it instead of as a css selector. Which is similar to my idea in #22014 not sure @sapphi-red if there can be any traction on this. I can work around it for now by adding an alias for each of my monorepo subpackages that have static assets just not ideal to have to maintain. Only thing that doesnt work nice with subpath imports at least for my codebase.
We discussed this issue in our last team meeting, and we're a bit concerned about introducing Vite-specific behavior here. We'd first like to understand how other bundlers handle this.
I would argue that Vite-specific behaviour for url(...) already exists — certain values are treated as asset imports while others are left untouched, and the distinction is implicit. Given this input...
The test isn't 'does this value already have a meaning?', it's 'can we resolve this value to a file in the project?'. So it feels inconsistent not to try and resolve subpath imports — yes, #x/y.png could theoretically be a fragment, in the same way that ./path/to/my/stuff/exists.png could theoretically refer to a path that's relative to the running app rather than the CSS file, but in practice it's vanishingly unlikely.
So as long as it's restricted to valid subpath imports and not anything with a leading #, resolving seems like the correct move.
Reacted by Andrew Kirwin, Kalven Schraut, 翠, Simon H and Scott Wu
Activity
bolt-new-by-stackblitz commentedon Mar 13, 2024
swwind commentedon Mar 24, 2024
Defining import map in
package.jsondoes not work currently.Manually edit
config.resolve.aliasif you want to map@assets/*to./src/assets/*in CSS. (#assets/*would not work because it was regarded as a hashtag)sapphi-red commentedon Mar 29, 2024
Simply resolving urls starting from
#will break things likemask: url(#star).https://stackblitz.com/edit/vitejs-vite-tt4mgn?file=src%2FApp.css
If we are going to make this work, we'll need to think about how not to break codes like above.
feat(vite): support subpath imports in css urls and only use if resol…
feat(vite): support subpath imports in css urls and only use if resol…
kalvenschraut commentedon Apr 20, 2026
https://github.com/vuejs/core/pull/13045/changes
vue implemented this for attributes with their own checks by what I think is seeing if the path resolves to a file then use it instead of as a css selector. Which is similar to my idea in #22014 not sure @sapphi-red if there can be any traction on this. I can work around it for now by adding an alias for each of my monorepo subpackages that have static assets just not ideal to have to maintain. Only thing that doesnt work nice with subpath imports at least for my codebase.
sapphi-red commentedon Jun 24, 2026
We discussed this issue in our last team meeting, and we're a bit concerned about introducing Vite-specific behavior here. We'd first like to understand how other bundlers handle this.
#...) in CSSurl('...')s #23261 as a duplicate of this issueRich-Harris commentedon Aug 17, 2026
I would argue that Vite-specific behaviour for
url(...)already exists — certain values are treated as asset imports while others are left untouched, and the distinction is implicit. Given this input......
vite buildwill generate this output (albeit minified):The test isn't 'does this value already have a meaning?', it's 'can we resolve this value to a file in the project?'. So it feels inconsistent not to try and resolve subpath imports — yes,
#x/y.pngcould theoretically be a fragment, in the same way that./path/to/my/stuff/exists.pngcould theoretically refer to a path that's relative to the running app rather than the CSS file, but in practice it's vanishingly unlikely.So as long as it's restricted to valid subpath imports and not anything with a leading
#, resolving seems like the correct move.