withastro/language-tools

๐Ÿ› BUG: astro-vscode extension .astro file(component) import error.

Closed this issue ยท 1 comments

Describe the Bug

The Astro vscode extension version 2.7.0 and above gives an error stating "Cannot find module '@/components/<component-name>' or its corresponding type declarations." while importing components.

image

tsconfig:

{
  "extends": "astro/tsconfigs/strict",
  "compilerOptions": {
    "strictNullChecks": true,
    "baseUrl": ".",
    "verbatimModuleSyntax": true,
    "paths": {
      "@/components/*": ["src/components/*.astro"],
      "@/layouts/*": ["src/layouts/*.astro"],
      "@/utils": ["src/utils/index.ts"],
      "@/data/*": ["src/data/*"],
      "@/site-config": ["src/data/site.config.ts"],
      "@/styles": ["src/styles/"],
    },
  },
  "exclude": ["node_modules", "**/node_modules/*", ".vscode", "dist"],
}

It was working fine until version 2.6.3.

Steps to Reproduce

  1. Upgrade Astro vscode extension to version 2.7.0 or above.
  2. Add a tsconfig.json file with the below configurations.
  "extends": "astro/tsconfigs/strict",
  "compilerOptions": {
    "strictNullChecks": true,
    "baseUrl": ".",
    "verbatimModuleSyntax": true,
    "paths": {
      "@/components/*": ["src/components/*.astro"],
      "@/layouts/*": ["src/layouts/*.astro"],
      "@/utils": ["src/utils/index.ts"],
      "@/data/*": ["src/data/*"],
      "@/site-config": ["src/data/site.config.ts"],
      "@/styles": ["src/styles/"],
    },
  },
  "exclude": ["node_modules", "**/node_modules/*", ".vscode", "dist", ".husky", ".astro"],
}
  1. Import any .astro component into the index.astro or any other component.
  2. Error! "Cannot find module '@/components/<component-name>' or its corresponding type declarations."

Duplicate of #778