跳转到内容

Upgrade to Astro v7

此内容尚不支持你的语言。

This guide will help you migrate from Astro v6 to Astro v7.

Need to upgrade an older project to v6 first? See our older migration guide.

Need to see the v6 docs? Visit this older version of the docs site (unmaintained v6 snapshot).

Update your project’s version of Astro to the latest version using your package manager:

Terminal window
# Upgrade Astro and official integrations together
npx @astrojs/upgrade alpha

You can also upgrade your Astro integrations manually if needed, and you may also need to upgrade other dependencies in your project.

Astro v7.0 includes potentially breaking changes, as well as the removal of some previously deprecated features.

If your project doesn’t work as expected after upgrading to v7.0, check this guide for an overview of all breaking changes and instructions on how to update your codebase.

See the Astro changelog for full release notes.

Astro v7.0 upgrades to Vite 8 as the development server and production bundler.

If you are using Vite-specific plugins, configuration, or APIs, check the Vite 8 migration guide for their breaking changes and upgrade your project as needed.

Most Astro users should be able to upgrade without any changes to their project code. This is primarily a breaking change for Astro integrations and plugins that depend on Vite internals.

Experimental flags allow you to opt in to features while they are in early development. The following experimental flags have been removed in Astro 7.0 and are now stable, or the new default behavior.

Remove these experimental flags from your Astro config if you were previously using them:

astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
experimental: {
rustCompiler: true,
advancedRouting: true,
routeCaching: true,
},
})
  • rustCompiler: The Rust-based Astro compiler is now the default and only compiler, replacing the previous Go-based compiler. No action is required for most projects. If you encounter any issues, please report them on GitHub.

  • advancedRouting: Advanced routing is now enabled by default. See the advanced routing reference for more information. Note that src/fetch.ts is now a reserved file name.

  • routeCaching: Route caching is now enabled by default for improved performance.

Astro v7.0 introduces advanced routing, which uses src/fetch.ts (or src/fetch.js) as a special file name, similar to src/middleware.ts. Astro will automatically import this file to configure routing behavior.

If your project already has a src/fetch.ts file used for other purposes, Astro will attempt to process it as an advanced routing configuration, which may cause unexpected errors.

If you have an existing src/fetch.ts file that is not related to advanced routing, you have two options:

Rename your file to something else (e.g. src/fetcher.ts, src/main.ts), and update any imports that reference it.

Disable advanced routing by setting fetchFile: null in your Astro config:

astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
fetchFile: null,
});

You can also point fetchFile to a different file name if you want to use advanced routing but need to keep src/fetch.ts for another purpose:

astro.config.mjs
import { defineConfig } from 'astro/config';
export default defineConfig({
fetchFile: './src/router.ts',
});

The @astrojs/db package has been removed in Astro v7.0 and is no longer maintained.

Remove @astrojs/db from your project’s dependencies and replace it with one of the following alternatives:

  • Node.js built-in SQLite: Node.js now includes a built-in node:sqlite module (available since Node.js v22.5.0). This is a good option if you are using the Node.js adapter and were using @astrojs/db for local SQLite storage.

  • Drizzle ORM: If you were using @astrojs/db for its Drizzle-based schema and query API, you can use Drizzle directly with any supported database.

  • Other database libraries: Use any database library that suits your deployment platform (e.g. Turso, PlanetScale, Neon).

贡献 社区 赞助