diff --git a/.changeset/nextjs16-optimizedeps-navigation.md b/.changeset/nextjs16-optimizedeps-navigation.md new file mode 100644 index 0000000..d00b71b --- /dev/null +++ b/.changeset/nextjs16-optimizedeps-navigation.md @@ -0,0 +1,5 @@ +--- +"vite-plugin-storybook-nextjs": patch +--- + +Fix missing Next.js 16 internal exports (`ServerInsertedHTMLContext`, `RedirectStatusCode`) in Vite dev mode by adding `next/navigation` and `next/dist/client/components/redirect-error` to `optimizeDeps.include` for Next.js 16+. See [storybookjs/storybook#34688](https://github.com/storybookjs/storybook/issues/34688). diff --git a/src/index.ts b/src/index.ts index 5872325..6628d80 100644 --- a/src/index.ts +++ b/src/index.ts @@ -182,6 +182,17 @@ function VitePlugin({ ? ["@emotion/react/jsx-dev-runtime"] : []), ...(isNext16orNewer ? [] : ["next/config"]), + // Next.js 16 ships internal re-export chains that Vite's esbuild + // pre-bundler fails to resolve in dev mode, causing missing exports + // like ServerInsertedHTMLContext and RedirectStatusCode. Forcing + // these modules to be pre-bundled fixes the resolution. + // See: https://github.com/storybookjs/storybook/issues/34688 + ...(isNext16orNewer + ? [ + "next/navigation", + "next/dist/client/components/redirect-error", + ] + : []), ], }, test: {