Sanity start fails: "Cannot find package 'next'" error in schema.js
This error occurs because your Sanity Studio's build process is trying to import the next package, but it's not installed in your Studio directory. This typically happens when there's a configuration mismatch or when you've accidentally imported something from Next.js in your Studio schema files.
Here are the steps to resolve this:
1. Check your schema.js file for Next.js imports
Look in schemas/schema.js (and any files it imports) for any lines that might be importing from 'next':
import something from 'next'
// or
import { something } from 'next/...'Sanity Studio and Next.js are separate applications - your Studio schema files shouldn't import anything from Next.js. If you find any such imports, remove them.
2. Check for accidental file mixing
Make sure you haven't accidentally copied code meant for your Next.js frontend into your Sanity Studio directory. The Studio should be in its own folder (often called studio/ or sanity/) separate from your Next.js app.
3. Clear cache and reinstall
Sometimes build caches can cause issues. Try:
# Remove node_modules and lock file
rm -rf node_modules
rm package-lock.json # or yarn.lock if using yarn
# Reinstall dependencies
npm install
# Try starting again
sanity start4. If you actually need Next.js in the same project
If you're working in a monorepo where both Studio and Next.js coexist, make sure they're in separate directories with their own package.json files, and you're running sanity start from the correct Studio directory.
The key insight here is that Sanity Studio is a React application that runs independently from your Next.js frontend. They should have separate dependencies and shouldn't cross-import from each other's packages. Your schema files should only use Sanity-specific imports.
If you're still stuck after trying these steps, share the contents of your schemas/schema.js file and your project structure - that would help identify where the Next.js reference is coming from.
Show original thread6 replies
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.