🔥 All-Access Pass — $199 USD (Regular $499) · Unlock all 2,836 Astro themes ➔
komal.nakrani
Get All-Access Pass ($199)
ThemesCategoriesDocsBlogTips & TricksPricingGet All-Access Pass ($199)
Astro Fundamentals••By Komal Nakrani

astro add: Install Astro Integrations in One Command

astro add installs an Astro integration or adapter, adds its peer dependencies and edits astro.config.mjs for you. Usage, --yes, third-party packages and fixes.

#Astro#astro add#CLI#Integrations

astro add is the Astro CLI command that installs an integration or adapter and wires it into your project in one step: npx astro add mdx installs @astrojs/mdx with its peer dependencies, imports it in astro.config.mjs and adds it to integrations. It asks before every change unless you pass --yes, and it accepts several names at once.

Key Takeaways

  • Usage: npx astro add <name> [more names], for example npx astro add react sitemap.
  • Short names resolve to official @astrojs/* packages first; other npm packages work if they’re tagged as Astro integrations.
  • Adapters such as node, netlify, vercel and cloudflare are set as adapter, not added to integrations.
  • --yes (or -y) accepts every prompt, which is what you want in scripts.

Basic usage

# terminal
npx astro add mdx

You can use your package manager’s runner too: pnpm astro add mdx, yarn astro add mdx or bunx astro add mdx. Astro detects which one you use and installs with it.

Add several at once and accept all prompts:

# terminal
npx astro add react mdx sitemap --yes

The result in your config:

// astro.config.mjs
import { defineConfig } from 'astro/config';
import react from '@astrojs/react';
import mdx from '@astrojs/mdx';
import sitemap from '@astrojs/sitemap';

export default defineConfig({
  integrations: [react(), mdx(), sitemap()],
});

Run npx astro add with no names to print the list of supported short names.

What it does, step by step

  1. Resolves the name. mdx is checked against the official @astrojs scope first. A scoped name like @scope/pkg goes straight to npm.
  2. Checks it’s an integration. The package’s keywords must include astro-integration or astro-adapter, or the command stops with “doesn’t appear to be an integration or an adapter”.
  3. Collects dependencies. Required peer dependencies are installed alongside it, so astro add react also installs react and react-dom.
  4. Edits your config. It shows a diff of astro.config.mjs and asks to apply it.
  5. Updates TypeScript settings when the integration needs them, for example JSX options for React, Preact or Solid.

Short names worth knowing

Command Installs
astro add react / preact / vue / svelte / solid-js UI framework renderers (solid also works)
astro add mdx / markdoc Content formats
astro add sitemap / partytown Build helpers
astro add tailwind Tailwind CSS 4 through @tailwindcss/vite
astro add starlight The Starlight docs framework
astro add node / netlify / vercel / cloudflare / deno Server adapters

Two of these do more than edit the config. tailwind registers @tailwindcss/vite as a Vite plugin and scaffolds src/styles/global.css, which you then import in your layout. cloudflare scaffolds a wrangler.jsonc if you don’t have one and adds a generate-types script that runs wrangler types.

Third-party integrations

Any npm package tagged astro-integration works:

# terminal
npx astro add astro-icon

Astro tells you it isn’t an official package and asks before continuing. Pin a version with the usual npm syntax, such as npx astro add @astrojs/mdx@latest.

When astro add can’t edit your config

astro add parses astro.config.mjs and modifies the defineConfig() call. If your config is built dynamically (spread from another file, wrapped in a function, or exported without defineConfig), it stops with “Astro could not update your astro.config.js file safely” and tells you to add the integration manually. Add the import and the integrations entry yourself, then run npm run dev to confirm. If there’s no config file at all, astro add creates one.

Komal themes keep a plain defineConfig() export, so astro add edits them like a fresh starter; astro.config.mjs in our docs shows the layout. For the full command list, see every Astro CLI command, and the sitemap tip for a worked example. If you’d rather start with integrations already configured, browse Astro themes. Astro’s CLI reference and the integrations directory list everything available.

FAQ

What does npx astro add do?

It installs an Astro integration or adapter with its peer dependencies and edits astro.config.mjs to register it, asking for confirmation before each change.

How do I install an Astro integration without prompts?

Add --yes or -y: npx astro add mdx --yes. Every prompt is accepted automatically, which is useful in setup scripts and CI.

Can I add multiple integrations at once?

Yes. List them with spaces: npx astro add react tailwind sitemap. Astro installs them in one go and shows a single config diff.

How do I remove an integration added with astro add?

There’s no astro remove. Uninstall the package with your package manager, then delete its import and its entry in integrations (or adapter) from astro.config.mjs.