Next.js Discord

Discord Forum

Monorepo: @workspace/ui components not resolving in Next.js 16 production build

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
I have a pnpm + Turborepo monorepo with the following structure:
apps/
  soon/   (Next.js 16)
  web/    (Next.js 16)
packages/
  ui/     (shared shadcn/ui components, source-only — no build step)

apps/soon/app/page.tsx imports:
import Logo from "@workspace/ui/components/Logo";


This fails during next build on Render with:
Module not found: Can't resolve '@workspace/ui/components/Logo'
packages/ui/package.json exports:
"exports": {
  "./globals.css": "./src/styles/globals.css",
  "./postcss.config": "./postcss.config.mjs",
  "./lib/*": "./src/lib/*",
  "./components/*": "./src/components/*",
  "./hooks/*": "./src/hooks/*"
}

apps/soon/next.config.ts:
const nextConfig: NextConfig = {
  transpilePackages: ["@workspace/ui"],
  outputFileTracingRoot: path.resolve(__dirname, "../../"),
  turbopack: {
    root: path.resolve(__dirname, "../../"),
  },
};

apps/soon/tsconfig.json paths:

"@workspace/ui/*": ["../../packages/ui/src/*"]


The file packages/ui/src/components/Logo.tsx exists. The build runs via Turborepo from the monorepo root so pnpm workspace symlinks are in place. Works fine locally in dev (next dev), only fails in production build on Render.
Questions:

- Do subpath pattern exports ("./components/*") work reliably with transpilePackages in Next.js 16 webpack builds?
- Does having turbopack: { root: ... } in next.config.ts change anything about how webpack resolves packages in next build?
- Is there anything special needed for pnpm workspace packages with transpilePackages in a CI environment?

0 Replies