To upgrade Astro between major versions, create a branch, check your Node.js version, run npx @astrojs/upgrade to bump Astro and every official integration together, then fix what the build and astro check report before testing the production output. If you are more than one major behind, upgrade one major at a time and read each version’s official upgrade guide, because breaking changes stack up.
This guide gives you a repeatable Astro upgrade process, a summary of the changes that cause the most work from Astro 4 through Astro 7, and the checks that catch problems before your visitors do.
Key Takeaways
npx @astrojs/upgradeupdatesastroand official@astrojs/*packages to compatible versions in one step.- Jumping several majors at once mixes unrelated errors; step through each major and build in between.
- The biggest historical migrations were content collections (Astro 5 and 6) and Markdown plugins (Astro 7).
astro check, a production build and a visual comparison of key pages catch nearly every regression.- Astro 7 needs Node.js 22.12 or newer (22.23.4 or newer for Astro 7.4.2 and later), locally and on your build host.
Before you start an Astro upgrade
A few minutes of preparation saves hours of guessing which change broke what:
- Work on a branch.
git switch -c upgrade-astro-7keepsmaindeployable. - Record the current version. Run
npx astro infoand save the output. It lists Astro, the adapter, integrations, Node.js and your package manager. The check Astro version tip covers other ways to see it. - Make sure the current site builds. Fix existing warnings first so new ones stand out.
- Note your critical pages. Home, a blog post, a page with islands, any form. You will compare them after the upgrade.
- Check Node.js. Astro 7.0 to 7.3 require Node.js 22.12 or newer; 7.4.0 and 7.4.1 need 22.22.0, and 7.4.2 and later need 22.23.4. Update your machine, CI image and host build settings, or pin it with a
.nvmrcfile.
# Terminal
node -v
npx astro info
git switch -c upgrade-astro-7
Run the upgrade tool
Astro’s upgrade CLI checks which official packages you use and installs matching versions, so you do not end up with an Astro 7 core and an adapter built for Astro 6:
# Terminal
npx @astrojs/upgrade
It works with npm, pnpm, Yarn and Bun, and prints links to the changelog of each package it updates. To target a specific release line, pass a tag, for example npx @astrojs/upgrade beta when testing a pre-release.
Third-party integrations are not covered. Check each one’s changelog for support for the new major and update it by hand:
# Terminal
npm outdated
npm install some-astro-integration@latest
Step through one major at a time
If your project is on Astro 4 and you want Astro 7, do not jump straight there. Upgrade to 5, build and fix, commit; then 6; then 7. Each official upgrade guide assumes you are coming from the previous major, and errors from three versions of changes at once are hard to untangle.
# Terminal
npm install astro@5 && npx astro build # fix, commit
npm install astro@6 && npx astro build # fix, commit
npx @astrojs/upgrade && npx astro build # latest 7.x, fix, commit
When pinning older majors manually, bump the official integrations to their matching major too.
The breaking changes that cause the most work
Every major has a long list of small changes. These are the ones that usually take real time:
| Upgrading to | What changes | What you do |
|---|---|---|
| Astro 5 | Content Layer API; collections defined with loaders in src/content.config.ts; output: 'hybrid' merged into static; ViewTransitions renamed ClientRouter |
Add loader: glob(...) to collections, move the config file, use render(entry) and entry.id, set prerender = false per route |
| Astro 6 | Legacy content collections removed; Astro.glob() removed |
Finish the collection migration; replace Astro.glob() with import.meta.glob() or getCollection() |
| Astro 7 | Vite 8 and Zod 4; Sätteri as the default Markdown processor; compressHTML follows JSX whitespace rules; src/fetch.ts treated as an entrypoint |
Move remark and rehype plugins into markdown.processor, import z from astro/zod, check inline spacing, rename any unrelated src/fetch.ts |
Content collections (Astro 5 and 6)
This was the largest migration in Astro’s history. A pre-5 collection looked like this:
// src/content/config.ts (before Astro 5)
import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
const blog = defineCollection({
type: 'content',
schema: z.object({ title: z.string() }),
});
export const collections = { blog };
In Astro 7 it moves to src/content.config.ts and gets an explicit loader:
// src/content.config.ts
import { defineCollection } from 'astro:content';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const blog = defineCollection({
loader: glob({ pattern: '**/*.{md,mdx}', base: './src/content/blog' }),
schema: z.object({ title: z.string() }),
});
export const collections = { blog };
Then replace entry.slug with entry.id and await entry.render() with await render(entry) imported from astro:content. If the old config file is still present, Astro 6 and later stop with the legacy content config error; the fix for legacy content config walks through it.
Markdown plugins (Astro 7)
Astro 7 uses Sätteri as its default Markdown processor. Top-level markdown.remarkPlugins and rehypePlugins still work but are deprecated. To keep a remark or rehype plugin, install @astrojs/markdown-remark and move it into unified():
// astro.config.mjs
import { defineConfig } from 'astro/config';
import { unified } from '@astrojs/markdown-remark';
import remarkToc from 'remark-toc';
export default defineConfig({
markdown: {
processor: unified({ remarkPlugins: [remarkToc] }),
},
});
Our Astro Markdown pipeline explainer covers both processors.
Test the upgrade properly
A successful build is necessary but not sufficient. Run these in order:
# Terminal
npx astro sync # regenerate content and env types
npx astro check # type errors, invalid props, schema issues
npm run build # production build, with warnings
npm run preview # serve dist/ locally
Then check by eye:
- Critical pages from your list. Compare against the live site side by side.
- Inline spacing. Astro 7’s
compressHTMLchange can remove spaces between inline elements that sit on separate lines in your templates, such as an icon and a label. - Islands. Click every interactive component; framework integrations sometimes need their own major bump.
- Markdown output. Headings, code blocks, footnotes and images, especially if you use plugins.
- Build output. Compare the list of files in
dist/before and after. A missing page usually means a route or collection filter changed.
Read the build log for deprecation warnings even if everything works. They are the next major’s breaking changes.
Upgrading a theme you bought
If your site started from a theme, you have two upgrade paths. You can upgrade your copy directly with the steps above, or pull the theme author’s updated version and merge it with your changes. The second is easier when the author has already done the migration. Every Komal theme runs Astro 7 and comes with free lifetime updates through its private repository, so merging upstream is usually the shorter route; our guide on customizing an Astro theme shows how to set up the upstream remote. If you are still choosing, the theme catalog lists what is current.
When not to upgrade right away
Upgrading promptly is good practice, but a few situations justify waiting a short while:
- A critical third-party integration has not released support yet. Track its issue tracker rather than forcing it.
- You are mid-launch. Ship first, upgrade after.
- The new major is days old. Waiting for the first patch release costs little.
Staying more than one major behind for long is what makes upgrades painful. Small, regular upgrades are cheaper than one large jump. The Astro config docs show the configuration file you will touch most often during an upgrade.
FAQ
How do I upgrade Astro to the latest version?
Run npx @astrojs/upgrade in your project. It updates astro and all official @astrojs/* integrations to compatible versions. Then run npx astro check and npm run build, fix any errors, and read the official upgrade guide for the new major.
Can I skip Astro major versions when upgrading?
You can, but it is harder. Breaking changes from several majors appear at once and each upgrade guide assumes the previous major. Stepping through each major, with a build and commit in between, is usually faster overall.
What breaks when upgrading from Astro 4 to Astro 5?
Mostly content collections, which move to the Content Layer API with loaders and src/content.config.ts, plus output: 'hybrid' merging into static, entry.slug becoming entry.id, and ViewTransitions being renamed ClientRouter.
How long does an Astro major upgrade take?
For a small static site on the previous major with official integrations only, often under an hour. Sites several majors behind, with many Markdown plugins, custom integrations or server features, can take a day or more.
How do I check which Astro version I am using?
Run npx astro --version for the version number, or npx astro info for Astro, the adapter, integrations, Node.js and package manager in one report.