Migration Guide
Migration Guide
This guide will help you migrate from Astro v2 to Astro v3.
## Upgrade Astro
Update your project's version of Astro to the latest version using your package
manager. If you're using Astro integrations, please also update those to the latest
version.
<PackageManagerTabs>
<Fragment slot="npm">
```shell
# Upgrade to Astro v3.x
npm install astro@latest
:::note[Need to continue?]
After upgrading Astro to the latest version, you may not need to make any changes
to your project at all!
But, if you notice errors or unexpected behavior, please check below for what has
changed that might need updating in your project.
:::
```js del={5-8}
// astro.config.mjs
import { defineConfig } from 'astro/config';
- View Transitions for animated page transitions and persistent islands. See [view
transitions API breaking changes and upgrading advice](/en/guides/view-
transitions/#upgrade-to-v30-from-v2x) if you were using this experimental flag.
- A new image services API `astro:assets` for using images in Astro, including a
new `<Image />` component and `getImage()` function. Please read the detailed
[image upgrade advice](/en/guides/images/#upgrade-to-v30-from-v2x) **whether or not
you were using this experimental flag** to see how this might affect your project.
Read more about these two exciting features and more in [the 3.0 Blog post]
(https://astro.build/blog/astro-3/)!
Astro v3.0 includes some breaking changes, as well as the removal of some
previously deprecated features. If your project doesn't work as expected after
upgrading to v3.0, check this guide for an overview of all breaking changes and
instructions on how to update your codebase.
Astro v3.0 drops Node 16 support entirely so that all Astro users can take
advantage of Node's more modern features.
Check that both your development environment and your deployment environment are
using **Node `18.14.1` or higher**.
```sh
node -v
```
2. Check your [deployment environment's](/en/guides/deploy/) own documentation to
verify that they support Node 18.
You can specify Node `18.14.1` for your Astro project either in a dashboard
configuration setting or a `.nvmrc` file.
```bash title=".nvmrc"
18.14.1
```
In Astro v2.x, the `tsconfig.json` presets include support for both TypeScript 4.x
and 5.x.
Astro v3.0 updates the `tsconfig.json` presets to only support TypeScript 5.x.
Astro now assumes that you use TypeScript 5.0 (March 2023), or that your editor
includes it (e.g. VS Code 1.77).
```bash
npm install typescript@latest --save-dev
```
In Astro v2.x, Astro offered an official image integration that included Astro
`<Image />` and `<Picture />` components.
Astro v3.0 removes this integration from the codebase entirely. Astro's new
solution for images is a built-in image services API: `astro:assets`.
Remove the `@astrojs/image` integration from your project. You will need to not
only uninstall the integration but also update or remove any import statements and
existing `<Image />` and `<Picture />` components. You might also need to configure
a preferred default image processing service.
You will find [complete, step-by-step instructions for removing the old image
integration](/en/guides/images/#remove-astrojsimage) in our Images guide.
Migrating to `astro:assets` will also bring some new image options and features
that you may now wish to use. Please see the full [v3.0 Image Upgrade
Advice](/en/guides/images/#upgrade-to-v30-from-v2x) for full details!
```js del={3,7}
// astro.config.mjs
import { defineConfig } from 'astro/config';
import image from '@astrojs/image';
In Astro v1.x, Astro deprecated the `<Markdown />` component and moved it to an
external package.
To continue using a similar `<Markdown />` component in your code, consider using
[community integrations](https://astro.build/integrations/) such as [`astro-
remote`](https://github.com/natemoo-re/astro-remote). Be sure to update your
`<Markdown />` component imports and attributes as necessary, according to the
integration's own documentation.
Otherwise, delete all references to importing Astro's `<Markdown />` component and
the component itself in your `.astro` files. You will need to rewrite your content
as HTML directly or [import Markdown](/en/guides/markdown-content/#importing-
markdown) from a `.md` file.
Astro v3.0 removes these deprecated APIs entirely. The officially supported
[configuration settings](/en/reference/configuration-reference/) and modern `<style
is:global>` and `<script>` syntax should be used instead.
If you are continuing to use v1.x APIs, use the new APIs for each feature instead:
In Astro v2.x, Astro provided partial shims for Web APIs such as `document` or
`localStorage` in server-rendered code. These shims were often incomplete and
unreliable.
Astro v3.0 removes these partial shims entirely. Web APIs are no longer available
in server-rendered code.
#### What should I do?
If you are using Web APIs in server-rendered components, you will need to either
make the usage of those APIs conditional or use [the `client:only` client
directive](/en/reference/directives-reference/#clientonly).
In Astro v2.x, the content collections API deprecated an `image` export from
`astro:content` for use in your content collections schemas.
If you are using the deprecated `image()` from `astro:content`, remove it as this
no longer exists. Validate images through [the `image` helper from
`schema`](/en/guides/images/#update-content-collections-schemas) instead:
defineCollection({
schema: ({ image }) =>
z.object({
image: image(),
}),
});
```
In Astro v2.x, some Shiki theme names had been renamed, but the original names were
kept for backwards compatibility.
Astro v3.0 removes the original names in favor of the renamed theme names.
If your project uses any of the themes below, rename them to their updated name:
Astro v3.0 now uses `clsx` directly for `class:list`, which does not support
deduplication or `Set` values.
#### What should I do?
Replace any `Set` elements passed to the `class:list` directive with a plain
`Array`.
Astro v3.0 normalizes `class:list` values into a string before being sent to
components via `Astro.props['class']`
Astro v3.0 removes the kebab-case transform for these camelCase CSS variable names,
and only the original camelCase CSS variable is rendered.
```astro "my-value"
---
// src/components/MyAstroComponent.astro
const myValue = "red"
---
<!-- input -->
<div style={{ "--myValue": myValue }}></div>
If you were relying on Astro to transform kebab-case in your styles, update your
existing styles to camelCase to prevent missing styles. For example:
Astro v3.0 moves the `astro check` command out of Astro core and now requires an
external package `@astrojs/check`. Additionally, you must install `typescript` in
your project to use the `astro check` command.
Run the `astro check` command after upgrading to Astro v3.0 and follow the prompts
to install the required dependencies, or manually install `@astrojs/check` and
`typescript` into your project.
Update the Astro config file to now use the new options **in the adapter
configuration** directly.
In Astro v2.x, the `markdown.drafts` configuration allowed you to have draft pages
that were available in when running the dev server, but not built in production.
Astro v3.0 deprecates this feature in favor of the content collections method of
handling draft pages by filtering manually instead, which gives more control over
the feature.
In Astro v2.x, endpoints could return a simple object, which would be converted to
a JSON response.
Astro v3.0 deprecates this behavior in favor of returning a `Response` object
directly.
If you really need to keep the previous format, you can use the
`ResponseWithEncoding` object but will be deprecated in the future.
This option requires that types are imported using the `import type` syntax.
While we recommend keeping it on and properly making your type imports with `type`
(as shown above), you can disable it by setting `verbatimModuleSyntax: false` in
your `tsconfig.json` file if it causes any issues.
If your `base` does not have a trailing slash, add one if you wish to preserve the
previous default (or `trailingSlash: "ignore"`) behavior:
You can now remove `compressHTML: true` from your configuration as this is the new
default behavior.
You must now set `compressHTML: false` to opt out of HTML compression.
### Changed default: `scopedStyleStrategy`
Astro v3.0 introduces a new, default value: `"attribute"`. By default, styles are
now applied using `data-*` attributes.
In Astro v2.x, all project stylesheets were sent as link tags by default. You could
opt in to inlining them into `<style>` tags every time with `"always"`, or to
inlining only stylesheets below a certain size with `"auto"` by setting the
[`build.inlineStylesheets`](/en/reference/configuration-reference/
#buildinlinestylesheets) configuration. The default setting was `"never"`.
Astro v3.0 now includes Sharp as the default image processing service and instead
provides a configuration option to use Squoosh.
#### What should I do?
:::note
When using a [strict package manager](https://pnpm.io/pnpm-vs-npm#npms-flat-tree)
like `pnpm`, you may need to manually install Sharp into your project even though
it is an Astro dependency:
```bash
pnpm add sharp
```
:::
If you would prefer to continue to use Squoosh to transform your images, update
your config with the following:
Astro v3.0 uses uppercase function names, including `DELETE` instead of `del`.
- `get` to `GET`
- `post` to `POST`
- `put` to `PUT`
- `all` to `ALL`
- `del` to `DELETE`
Astro v3.0 now requires you to specify which framework to use for your files with
new `include` and `exclude` integration config options when you have multiple JSX
framework integrations installed. This allows Astro to better support single-
framework usage, as well as advanced features like React Fast Refresh.
If you are using multiple JSX frameworks in the same project, set `include` (and
optionally `exclude`) to an array of files and/or folders. Wildcards may be used to
include multiple file paths.
```js ins={13,16,19}
import { defineConfig } from 'astro/config';
import preact from '@astrojs/preact';
import react from '@astrojs/react';
import svelte from '@astrojs/svelte';
import vue from '@astrojs/vue';
import solid from '@astrojs/solid-js';
In Astro v2.x,
[`Astro.cookies.get(key)`](/en/reference/api-reference/#astrocookies) would always
return an [`AstroCookie` object](/en/reference/api-reference/#astrocookie), even if
the cookie did not exist. To check for its existence, you needed to use
`Astro.cookies.has(key)`.
Astro v3.0 returns `undefined` for `Astro.cookies.get(key)` if the cookie does not
exist.
This change will not break any code that checks for the existence of the
`Astro.cookie` object before using `Astro.cookies.get(key)`, but is now no longer
required.
You can safely remove any code that uses `has()` to check if the value of
`Astro.cookies` is `undefined`:
const id = Astro.cookies.get(id);
if (id) {
}
```
In Astro v2.x, the `"astro"` package entrypoint exported and ran the Astro CLI
directly. It is not recommended to run Astro this way in practice.
Astro v3.0 removes the CLI from the entrypoint, and exports a new set of
experimental JavaScript APIs, including `dev()`, `build()`, `preview()`, and
`sync()`.
```js
import { dev, build } from "astro";
In Astro v2.x, you could import internal Astro APIs from `astro/internal/*` and
`astro/runtime/server/*`.
Astro v3.0 removes the two entry points in favor of the existing `astro/runtime/*`
entrypoint. Additionally, a new `astro/compiler-runtime` export has been added for
compiler-specific runtime code.
These are entry points for Astro's internal API and should not affect your project.
But if you do use these entrypoints, update as shown below:
import 'astro/server/index.js';
import 'astro/runtime/server/index.js';
```
## Community Resources
## Known Issues