Module not found errors for @sanity/ packages in Storybook example project
The Sanity repository examples are designed to work within the monorepo context using pnpm workspaces, not as standalone projects. The examples/storybook directory you're trying to run depends on internal workspace references to other packages in the monorepo, which is why you're seeing all those @sanity/ module resolution errors.
Here's what's happening: The example expects to resolve @sanity/* packages from the monorepo's internal workspace packages (like @sanity/ui, @sanity/icons, etc.), not from npm. When you try to run it in isolation with npm, yarn, or even lerna bootstrap, these workspace dependencies can't be resolved correctly because the workspace structure isn't set up properly.
To run the Storybook example properly:
Clone the entire Sanity repository (if you haven't already):
git clone https://github.com/sanity-io/sanity.git cd sanitySwitch to the
nextbranch (since that's where you found the example):git checkout nextInstall pnpm if you don't have it:
npm install -g pnpmInstall all dependencies from the root of the monorepo:
pnpm installBuild the monorepo packages that the Storybook example depends on:
pnpm buildNavigate to the Storybook example and run it:
cd examples/storybook pnpm dev
The key insight is that Sanity's monorepo uses pnpm workspaces, and the examples are meant to demonstrate usage patterns for contributors or those exploring the Sanity codebase, not necessarily as copy-paste starter templates.
If you're looking to use Sanity with Storybook in your own project, you'd want to install the published npm packages (@sanity/ui, @sanity/icons, etc.) directly in your project rather than trying to extract the example. You can use the example code as a reference for how to configure stories and components, but start with a fresh project and install the Sanity packages you need from npm using npm install @sanity/ui or similar.
The examples folder in the Sanity repository is primarily for internal development and demonstration purposes within the monorepo structure.
Show original thread17 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.