css: resolve bare module specifiers in @import to node_modules#485
Merged
aeschli merged 1 commit intoApr 8, 2026
Merged
Conversation
Enable node_modules fallback resolution for CSS @import, matching the existing behavior in SCSS and LESS. Also fix getModuleNameFromPath to return the full path for bare specifiers without a slash (e.g. @import "bootstrap") instead of returning an empty string. Fixes microsoft/vscode#295074 Signed-off-by: Vijay Govindarajan <vijay.govindarajan91@gmail.com>
Contributor
Author
Contributor
Author
|
@aeschli moved here from microsoft/vscode#305900 per your feedback. All 709 tests passing. |
aeschli
approved these changes
Mar 31, 2026
alexr00
approved these changes
Mar 31, 2026
Contributor
Author
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes microsoft/vscode#295074
Summary
CSS
@importstatements with bare module specifiers (e.g.@import "foo/bar.css") currently do not resolve tonode_modules, even though SCSS and LESS already support this. This PR fixes two issues:Enable
resolveModuleReferencesfor CSS — the node_modules fallback path was disabled for CSS (false) while SCSS and LESS both had it enabled (true). This aligns CSS with the existing behavior.Fix
getModuleNameFromPath()for bare specifiers — the function returned an empty string for module names without a slash (e.g."bootstrap"), causing resolution to silently fail. It now returns the full path as the module name.This was originally attempted in microsoft/vscode#305900 at the
getDocumentContextlevel, but @aeschli pointed out it belongs here in the language service.Changes
src/cssLanguageService.tsresolveModuleReferences: trueforgetCSSLanguageService()src/services/cssNavigation.tsgetModuleNameFromPath()when no slash presentsrc/test/css/navigation.test.tstest/linksTestFixtures/node_modules/foo/bar.cssTest plan
@import "foo/bar.css"resolves tonode_modules/foo/bar.css~foo/hello.html) continues to work