Issue with embedding Sanity Studio into an Astro site, resolved with help from the community.
I can see the issue! You're using the wrong npm package. The astro-sanity package you have in your config is an unofficial/older community package, but Sanity has an official integration called @sanity/astro that you should be using instead.
Here's what you need to do:
1. Uninstall the old package and install the official one:
npm uninstall astro-sanity
npm install @sanity/astro2. Update your astro.config.mjs:
import { defineConfig } from 'astro/config';
import tailwind from '@astrojs/tailwind';
import svelte from '@astrojs/svelte';
import sanity from '@sanity/astro'; // Changed this line
import react from '@astrojs/react';
import netlify from "@astrojs/netlify/functions";
export default defineConfig({
output: 'hybrid',
integrations: [
tailwind(),
svelte(),
sanity({
projectId: '<actualProjectID>',
dataset: 'production',
useCdn: false,
studioBasePath: '/admin'
}),
react()
],
adapter: netlify()
});3. Verify your Studio setup:
Make sure your admin folder contains a proper Sanity Studio setup with:
sanity.config.ts(or.js) file- Your schema types
- Proper basePath configuration in the Studio config
The official Astro documentation shows the correct setup process. The @sanity/astro package is the maintained, official integration that properly handles embedding the Studio at a custom path like /admin.
The 404 error you're experiencing is likely because astro-sanity doesn't have the same Studio embedding capabilities as the official @sanity/astro package. After switching packages, your /admin route should work correctly!
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.