Skip to content

Image Preview fails to resolve path aliases defined in jsconfig.json (e.g., @/) #6006

@sweetwisdom

Description

@sweetwisdom

What problem does this feature solve?

  • VS Code Version: 1.112.0
  • OS Version: macos arm64 25.3.0

Description:
The built-in Image Preview extension does not seem to recognize path mappings defined in jsconfig.json or tsconfig.json. When using an alias like @/ inside an img tag’s src attribute, VS Code fails to load the image and displays an error, even though the path is correctly resolved by the build tool (e.g., Vite/Rsbuild/Webpack) at runtime.

What does the proposed solution look like?

Steps to Reproduce:

Image

Configure Alias: Add a path mapping in jsconfig.json at the project root
jsconfig:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "baseUrl": "./",
    "allowJs": true,
    "moduleResolution": "node",
    "jsx": "preserve",
    "paths": {
      "@/*": ["src/*"]
    },
    "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
  },
  "vueCompilerOptions": {
    "target": 2.7
  }
}

Hover over the image tag or try to open the image side-by-side.
Observed Result: The image preview shows the error message: An error occurred while loading the image.
Expected Result: The image should preview correctly, resolving @/ to the src/ directory, similar to how JavaScript imports work.
Additional Context:

The path resolution works correctly in JS/TS import statements (Ctrl+Click navigates correctly).
The issue only occurs in template contexts (HTML/Vue tags).

Image

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions