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
VSCode can't resolve file imports in SCSS that refer to node modules.
If the file in which the import is declared is not in the root folder containing node modules, VSCode tries to resolve this path by relative link. That is, if the file is in, say, project/test.scss, it will be opened in project/@example/theme/theming. If the file does not exist, VSCode should try to find it in the node modules.
I've looked at the source code a bit, and found the specific place where the error occurs:
protected async resolvePathToModule(_moduleName: string, documentFolderUri: string, rootFolderUri: string | undefined): Promise<string | undefined> {
// resolve the module relative to the document. We can't use `require` here as the code is webpacked.
const packPath = joinPath(documentFolderUri, 'node_modules', _moduleName, 'package.json');
if (await this.fileExists(packPath)) {
return dirname(packPath);
} else if (rootFolderUri && documentFolderUri.startsWith(rootFolderUri) && (documentFolderUri.length !== rootFolderUri.length)) {
return this.resolvePathToModule(_moduleName, dirname(documentFolderUri), rootFolderUri);
}
return undefined;
}
documentFolderUri.startsWith(rootFolderUri) compares the document uri and the root uri. The problem is that the client sends the encoded document uri to the language server:
The root uri is not encoded, because documentFolderUri parameter was set with dirname function on documentUri:
export function dirname(uriString: string): string {
return Utils.dirname(URI.parse(uriString)).toString(true);
}
The toString function has a true parameter, which means the uri will not be encoded. Therefore an error occurs in resolvePathToModule because undefined is returned.
I also looked at unit tests under the ‘SCSS node module resolving’ category. There the document uri is not encoded, so no error occurs. I don't know if this is a bug with the laguage service or VSCode passing an unencoded uri, so I am posting the issue here
Does this issue occur when all extensions are disabled?: Yes
VS Code Version: 1.98.2
OS Version: Windows Pro 11 23H2
Steps to Reproduce:
Install some npm theming package with SCSS
Create new directory
Create new SCSS file in this directory
Import some SCSS file from node package like that: @import "@example/theme/theming";
Unable to open 'theming', vscode tries to find this module in directory where SCSS file is located
The text was updated successfully, but these errors were encountered:
VSCode can't resolve file imports in SCSS that refer to node modules.
If the file in which the import is declared is not in the root folder containing node modules, VSCode tries to resolve this path by relative link. That is, if the file is in, say,
project/test.scss
, it will be opened inproject/@example/theme/theming
. If the file does not exist, VSCode should try to find it in the node modules.I've looked at the source code a bit, and found the specific place where the error occurs:
vscode-css-languageservice/src/services/cssNavigation.ts - resolvePathToModule
documentFolderUri.startsWith(rootFolderUri)
compares the document uri and the root uri. The problem is that the client sends the encoded document uri to the language server:The root uri is not encoded, because
documentFolderUri
parameter was set with dirname function ondocumentUri
:The
toString
function has a true parameter, which means the uri will not be encoded. Therefore an error occurs in resolvePathToModule because undefined is returned.I also looked at unit tests under the ‘SCSS node module resolving’ category. There the document uri is not encoded, so no error occurs. I don't know if this is a bug with the laguage service or VSCode passing an unencoded uri, so I am posting the issue here
Does this issue occur when all extensions are disabled?: Yes
Steps to Reproduce:
@import "@example/theme/theming";
The text was updated successfully, but these errors were encountered: