Module not found errors for @sanity/ packages in Storybook example project

17 replies
Last updated: Jan 27, 2026
Hi, I'm trying to run the Storybook project from the Sanity examples directory (https://github.com/sanity-io/sanity/tree/next/examples/storybook ). After installing all dependencies (tried
lerna bootstrap
and
npm
as well as
yarn
), and starting the server, I get many Module not found: Error: Can't resolve
@sanity/
related errors - at least 32 of them - even if the dependencies seem to be installed correctly.
AI Update

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:

  1. Clone the entire Sanity repository (if you haven't already):

    git clone https://github.com/sanity-io/sanity.git
    cd sanity
  2. Switch to the next branch (since that's where you found the example):

    git checkout next
  3. Install pnpm if you don't have it:

    npm install -g pnpm
  4. Install all dependencies from the root of the monorepo:

    pnpm install
  5. Build the monorepo packages that the Storybook example depends on:

    pnpm build
  6. Navigate 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 thread
17 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.

Was this answer helpful?