Skip to content

css: resolve bare module specifiers in @import to node_modules#485

Merged
aeschli merged 1 commit into
microsoft:mainfrom
vijaygovindaraja:fix/css-bare-module-import-resolution
Apr 8, 2026
Merged

css: resolve bare module specifiers in @import to node_modules#485
aeschli merged 1 commit into
microsoft:mainfrom
vijaygovindaraja:fix/css-bare-module-import-resolution

Conversation

@vijaygovindaraja
Copy link
Copy Markdown
Contributor

Fixes microsoft/vscode#295074

Summary

CSS @import statements with bare module specifiers (e.g. @import "foo/bar.css") currently do not resolve to node_modules, even though SCSS and LESS already support this. This PR fixes two issues:

  1. Enable resolveModuleReferences for 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.

  2. 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 getDocumentContext level, but @aeschli pointed out it belongs here in the language service.

Changes

File Change
src/cssLanguageService.ts Set resolveModuleReferences: true for getCSSLanguageService()
src/services/cssNavigation.ts Return full path from getModuleNameFromPath() when no slash present
src/test/css/navigation.test.ts Add test for bare module specifier resolution
test/linksTestFixtures/node_modules/foo/bar.css Test fixture

Test plan

  • All 709 existing tests pass
  • New test: @import "foo/bar.css" resolves to node_modules/foo/bar.css
  • Existing tilde-prefix resolution (~foo/hello.html) continues to work
  • Local file resolution takes precedence over node_modules fallback

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>
@vijaygovindaraja
Copy link
Copy Markdown
Contributor Author

@aeschli

@vijaygovindaraja
Copy link
Copy Markdown
Contributor Author

@aeschli moved here from microsoft/vscode#305900 per your feedback. All 709 tests passing.

@vijaygovindaraja
Copy link
Copy Markdown
Contributor Author

Hey @aeschli @alexr00 — noticed this has two approvals, is there anything else needed before it can land?

@aeschli aeschli merged commit 0f4cf27 into microsoft:main Apr 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CSS] Support click links in @import '<module>' to node_modules

3 participants