The best Astro VS Code setup starts with one thing: the official Astro extension (astro-build.astro-vscode), which adds syntax highlighting, autocompletion, type checking and go-to-definition for .astro files. Add Prettier with prettier-plugin-astro for formatting, ESLint with eslint-plugin-astro for linting, and the MDX and Tailwind CSS IntelliSense extensions if your project uses them.
This guide walks through each piece, with the exact settings files to commit so everyone on a project gets the same editor behavior.
Key Takeaways
- Install the official Astro extension first. It powers language features through the Astro language server.
- Keep
tsconfig.jsonextendingastro/tsconfigs/strictand include.astro/types.d.tsso collection and env types resolve.- Format with Prettier plus
prettier-plugin-astro, and lint witheslint-plugin-astro.- Commit
.vscode/extensions.jsonand.vscode/settings.jsonso the setup travels with the repo.- Run
astro checkin CI to catch the same type errors the editor shows.
Step 1: install the Astro extension
Open the Extensions panel, search for “Astro”, and install the extension published by Astro (identifier astro-build.astro-vscode). Or from a terminal:
code --install-extension astro-build.astro-vscode
It gives you:
- Syntax highlighting for frontmatter, template expressions,
<style>and<script>blocks. - Autocompletion for HTML, components, props and
client:*directives. - Type checking of
Astro.props, imports and expressions inside the template. - Go to definition and rename across
.astro,.tsand framework files. - Formatting through Prettier, when the plugin is installed.
Projects created with npm create astro@latest include a .vscode/extensions.json that recommends it, so VS Code prompts new contributors to install it. If you are brand new to Astro, the Astro tutorial for beginners covers project creation first.
Step 2: check your TypeScript config
The editor’s type checking reads tsconfig.json. Astro ships presets, and the default starter uses the strict one:
// tsconfig.json
{
"extends": "astro/tsconfigs/strict",
"include": [".astro/types.d.ts", "**/*"],
"exclude": ["dist"]
}
Three presets are available: base, strict and strictest. strict is a good default for themes and client sites. The .astro/types.d.ts include is what makes astro:content, astro:env and other virtual modules typed. That file is generated by astro dev or astro sync, so if imports from astro:content show red squiggles, run:
npx astro sync
Path aliases also live here. Adding "paths": { "@/*": ["src/*"] } under compilerOptions lets you write import Button from '@/components/Button.astro', and the extension follows it. The path aliases tip shows the full setup.
Step 3: format with Prettier
Prettier doesn’t understand .astro files on its own. Add the plugin:
npm install --save-dev prettier prettier-plugin-astro
// .prettierrc
{
"plugins": ["prettier-plugin-astro"],
"overrides": [
{
"files": "*.astro",
"options": { "parser": "astro" }
}
]
}
Install the Prettier extension (esbenp.prettier-vscode) and set it as the default formatter for Astro files in your workspace settings (shown in step 6). If you use Tailwind CSS, add prettier-plugin-tailwindcss after the Astro plugin in the plugins array to sort class names automatically.
Step 4: lint with ESLint
eslint-plugin-astro adds Astro-aware rules, including accessibility checks for .astro templates through its jsx-a11y integration:
npm install --save-dev eslint eslint-plugin-astro typescript-eslint
// eslint.config.js
import eslintPluginAstro from 'eslint-plugin-astro';
import tseslint from 'typescript-eslint';
export default [
...tseslint.configs.recommended,
...eslintPluginAstro.configs.recommended,
{
ignores: ['dist/', '.astro/'],
},
];
Install the ESLint extension (dbaeumer.vscode-eslint) to see problems inline. The flat config format above is what current ESLint versions expect. The ESLint and Prettier tip covers combining the two without conflicts.
Step 5: extensions for MDX and Tailwind CSS
Add these only if your project uses them:
| Extension | Identifier | Why |
|---|---|---|
| Astro | astro-build.astro-vscode |
Core language support |
| Prettier | esbenp.prettier-vscode |
Formatting |
| ESLint | dbaeumer.vscode-eslint |
Lint errors inline |
| MDX | unifiedjs.vscode-mdx |
Highlighting and IntelliSense for .mdx |
| Tailwind CSS IntelliSense | bradlc.vscode-tailwindcss |
Class autocompletion and hover previews |
| Error Lens (optional) | usernamehw.errorlens |
Shows errors at the end of the line |
Tailwind CSS IntelliSense works in .astro files out of the box once it detects your Tailwind config or CSS entry. If completions don’t appear inside class:list arrays, add a classRegex setting, or rely on the plain class attribute where possible.
Step 6: commit workspace settings
Put shared settings in the repository so every contributor and every new machine gets the same behavior:
// .vscode/extensions.json
{
"recommendations": [
"astro-build.astro-vscode",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"unifiedjs.vscode-mdx",
"bradlc.vscode-tailwindcss"
],
"unwantedRecommendations": []
}
// .vscode/settings.json
{
"editor.formatOnSave": true,
"[astro]": {
"editor.defaultFormatter": "astro-build.astro-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[mdx]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"eslint.validate": ["javascript", "typescript", "astro"],
"files.exclude": {
"**/.astro": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}
The Astro extension formats .astro files using your project’s Prettier config, which is why it’s the default formatter for [astro]. Hiding .astro in the file explorer keeps generated types out of the way; they still work. typescript.tsdk makes VS Code use the project’s TypeScript version rather than the one bundled with the editor.
Step 7: debug the dev server
Astro starters include a launch configuration. If yours doesn’t, add it:
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"command": "./node_modules/.bin/astro dev",
"name": "Development server",
"request": "launch",
"type": "node-terminal"
}
]
}
Press F5 and VS Code starts astro dev with the debugger attached. Breakpoints in frontmatter, endpoints and middleware pause on the server side, which is very useful for getStaticPaths() and API routes. Browser code (<script> tags and islands) is debugged in the browser’s devtools instead.
Step 8: type check from the terminal and CI
The editor only checks files you open. astro check checks the whole project with the same language server:
npm install --save-dev @astrojs/check typescript
npx astro check
Add it to your build script so type errors fail the build:
// package.json (excerpt)
{
"scripts": {
"dev": "astro dev",
"build": "astro check && astro build",
"preview": "astro preview"
}
}
astro check --watch runs continuously in a terminal panel if you prefer that to editor squiggles. The astro check command tip explains its flags, and the official editor setup docs list support for other editors such as JetBrains IDEs, Zed and Neovim.
Minimal setup vs full setup
You don’t need every tool on day one. A sensible progression:
- Solo, small site: the Astro extension and
tsconfig.jsonfrom the starter. Nothing else. - Anything you’ll maintain: add Prettier with
prettier-plugin-astroand format on save, so diffs stay clean. - A team or a client handover: add ESLint, the committed
.vscode/files andastro checkin the build script, so problems are caught before review rather than in it.
Each step adds a few minutes of setup and removes a category of mistakes. The full version above is what you want on any project that more than one person touches.
Troubleshooting common editor problems
- No highlighting in
.astrofiles. The Astro extension isn’t installed or is disabled in this workspace. Cannot find module 'astro:content'. Runnpx astro syncand check thattsconfig.jsonincludes.astro/types.d.ts.- Props show as
any. Declareinterface Propsin the component frontmatter. - Formatting does nothing. Check
prettier-plugin-astrois installed locally and listed inplugins. - The extension is slow on a large repo. Exclude
dist/andnode_modules/from the TypeScript project, and close files you aren’t using.
A consistent editor setup pays off most when you’re editing code someone else wrote. Every one of the Komal Astro themes is a standard Astro 7 project with TypeScript, so the setup above works on them unchanged, and the getting started docs cover cloning a theme and running it locally.
FAQ
What is the best VS Code extension for Astro?
The official Astro extension, astro-build.astro-vscode. It provides syntax highlighting, IntelliSense, type checking and formatting for .astro files through the Astro language server. Add Prettier, ESLint, MDX and Tailwind CSS extensions as your project needs them.
Why does VS Code show errors for astro:content imports?
The types for Astro’s virtual modules are generated into .astro/types.d.ts. Run npx astro sync or start the dev server, and make sure tsconfig.json includes that file. Restart the TypeScript server from the command palette if the errors persist.
How do I format Astro files with Prettier?
Install prettier and prettier-plugin-astro, list the plugin in your Prettier config, and set the Astro extension as the default formatter for [astro] files in .vscode/settings.json. Turn on editor.formatOnSave to format automatically.
Can I debug Astro in VS Code?
Yes. Add a launch configuration that runs astro dev as a node-terminal, then press F5. Breakpoints in frontmatter, endpoints and middleware will pause. Client-side scripts are debugged in the browser devtools.
Does the Astro VS Code extension check types?
Yes, for open files. For the whole project, install @astrojs/check and run npx astro check, which uses the same engine and is suitable for CI.