# Migration Guide: Astro v6 → v7 > Official reference: https://docs.astro.build/en/guides/upgrade-to/v7/ --- ## 1. Pre-Migration Checklist - [ ] **Backup** — commit all changes, create a branch: `git checkout -b feat/astro-v7-upgrade` - [ ] **Node.js ≥ 22** — required (v22.5.0+ for `node:sqlite` if replacing `@astrojs/db`) ```bash node -v # must be >= 22 ``` - [ ] **Audit dependencies** — check for packages that depend on Vite internals or the Go compiler ```bash npx astro info ``` - [ ] **Review remark/rehype plugins** — if you have any, plan for Sätteri migration or `@astrojs/markdown-remark` fallback - [ ] **Check for `src/fetch.ts`** — if this file exists for non-routing purposes, plan a rename - [ ] **Check for `@astrojs/db`** usage — plan a replacement (Drizzle, node:sqlite, Turso, Neon) --- ## 2. Upgrade Commands ```bash # npm npx @astrojs/upgrade # pnpm pnpm dlx @astrojs/upgrade # yarn yarn dlx @astrojs/upgrade ``` This upgrades Astro and all official integrations together. For manual control: ```bash npm install astro@latest npm install @astrojs/react@latest @astrojs/mdx@latest # repeat for each integration ``` --- ## 3. Breaking Changes ### 3.1 Vite 8 Astro v7 upgrades to [Vite 8](https://vite.dev/blog/announcing-vite8). The main impact is on **custom Vite plugins** and projects using Vite internals directly. Key Vite 8 changes: - **esbuild → Rolldown** as the production bundler (Rolldown is a Rust-based Rollup replacement) - Plugin API surface changes — check the [Vite 8 migration guide](https://vite.dev/guide/migration) **What to do:** - If you have custom Vite plugins in `astro.config.mjs`, verify they work with Vite 8 - If you use `esbuild`-specific options (e.g. `esbuild.target`, `esbuild.jsxFactory`), check if they still apply under Rolldown ```js // Before: esbuild-specific config (may need review) export default defineConfig({ vite: { esbuild: { target: 'esnext', jsxFactory: 'h', }, }, }); // After: verify compatibility — most configs carry over, but test your build export default defineConfig({ vite: { // Rolldown handles bundling; esbuild options may behave differently // Test `astro build` and check output }, }); ``` > **Most Astro users need no changes.** This primarily affects integration authors and projects with custom Vite plugins. --- ### 3.2 Rust Compiler The Rust-based compiler is now the **default and only compiler**, replacing the Go-based compiler. It is stricter about HTML syntax. #### Unclosed tags now produce errors ```astro
Hello world
Hello world
``` ```astro --- import Layout from '../layouts/Layout.astro'; ---Content here
Content here
`, ``, ``, `
`). The Rust compiler passes markup through as-is. ```astro
`, etc.) - ❌ Missing spaces between inline elements → add `{' '}` where needed - ❌ Markdown rendering issues → install `@astrojs/markdown-remark` if using remark/rehype plugins - ❌ Build errors mentioning `src/fetch.ts` → rename or set `fetchFile: null` - ❌ Import errors for `@astrojs/db` → replace with alternative DB solution - ❌ Import errors for `TRANSITION_*` constants → use event name strings directly --- ## Quick Reference: Search & Replace | Find | Replace with | |---|---| | `from '@astrojs/react'` (for getContainerRenderer) | `from '@astrojs/react/container-renderer'` | | `TRANSITION_BEFORE_PREPARATION` | `'astro:before-preparation'` | | `TRANSITION_AFTER_PREPARATION` | `'astro:after-preparation'` | | `TRANSITION_BEFORE_SWAP` | `'astro:before-swap'` | | `TRANSITION_AFTER_SWAP` | `'astro:after-swap'` | | `TRANSITION_PAGE_LOAD` | `'astro:page-load'` | | `isTransitionBeforePreparationEvent(e)` | `e.type === 'astro:before-preparation'` | | `isTransitionBeforeSwapEvent(e)` | `e.type === 'astro:before-swap'` | | `createAnimationScope` | (remove entirely) | | `experimental.rustCompiler` | (remove) | | `experimental.queuedRendering` | (remove) | | `experimental.advancedRouting` | (remove) | --- ## Ecosystem Compatibility (learned from real upgrades) ### Starlight 0.40+ Sidebar Schema Change Starlight 0.40 (required for Astro v7) changed the sidebar schema. `autogenerate` can no longer be a direct property of a sidebar group — it must be inside `items`: ```javascript // BEFORE (Starlight 0.38): { label: 'Reference', autogenerate: { directory: 'reference' } } // AFTER (Starlight 0.40): { label: 'Reference', items: [{ autogenerate: { directory: 'reference' } }] } ``` ### astro-mermaid — Incompatible with v7 `astro-mermaid` (all versions through 2.0.4) uses `isUnifiedProcessor()` which was removed in Astro v7. Replace with Mermaid CDN client-side script: ```javascript // In Starlight head config or Layout.astro: { tag: 'script', attrs: { type: 'module' }, content: ` import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs'; mermaid.initialize({ startOnLoad: false }); document.addEventListener('DOMContentLoaded', () => { document.querySelectorAll('pre > code.language-mermaid').forEach((el) => { const pre = el.parentElement; const div = document.createElement('div'); div.className = 'mermaid'; div.textContent = el.textContent; pre.replaceWith(div); }); mermaid.run(); }); `, } ``` ### Docker Alpine — Sätteri native binding missing Sätteri only ships `linux-x64-gnu` (glibc). Alpine uses musl. Build stage MUST use `node:22-slim`: ```dockerfile FROM node:22-slim AS build # NOT alpine ``` ### .npmrc required in Dockerfile Astro v7 with Starlight plugins causes peer dependency conflicts. The `.npmrc` with `legacy-peer-deps=true` must be copied into Docker: ```dockerfile COPY package*.json .npmrc ./ RUN npm ci ``` ### @astrojs/node Must Be v11 for Astro v7 `@astrojs/node@10` builds fine but **crashes at runtime** with Astro v7: ``` TypeError: app.getAdapterLogger is not a function at createAppHandler (dist/server/entry.mjs) ``` The build succeeds, the image is created, the container starts — then immediately exits. Coolify shows `restarting:unknown` or `exited:unhealthy`. **Fix:** Always upgrade `@astrojs/node` alongside Astro: ```bash npm install astro@latest @astrojs/node@latest @astrojs/mdx@latest ``` **Required versions for v7:** | Package | Minimum | |---------|---------| | `astro` | `^7.0.0` | | `@astrojs/node` | `^11.0.0` | | `@astrojs/mdx` | `^7.0.0` | | `@astrojs/sitemap` | `^3.7.2` (unchanged) | ### pnpm 11.9+ — approve-builds Required in Docker pnpm 11.9 blocks postinstall scripts by default. `esbuild` and `sharp` need native compilation after install. Without approval the Docker build fails: ``` [ERR_PNPM_IGNORED_BUILDS] Ignored build scripts: esbuild@0.28.1, sharp@0.34.5 ``` **Fix:** Run `pnpm approve-builds` locally (generates `pnpm-workspace.yaml`), then copy it in Docker: ```dockerfile COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./ RUN pnpm install --frozen-lockfile ```