-
Notifications
You must be signed in to change notification settings - Fork 30.8k
turbopack.root does not apply to PostCSS child process module resolution in npm workspace setup #92060
Description
Description
When using Next.js 16 (with Turbopack as the default for next build) inside an npm workspace monorepo, setting turbopack.root to the workspace root does not fix module resolution for PostCSS transforms.
The PostCSS transform runs in a separate Node.js child process, and it appears that turbopack.root is not applied to that process's module resolution scope.
Reproduction
Repository structure:
```
/app/ ← workspace root
├── package.json ← npm workspace config
├── node_modules/ ← hoisted packages (includes @tailwindcss/postcss)
├── frontend/ ← Next.js app
│ ├── package.json
│ ├── next.config.ts
│ ├── postcss.config.mjs ← uses @tailwindcss/postcss
│ └── src/
└── backend/
└── package.json
```
next.config.ts:
```ts
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
output: 'standalone',
turbopack: {
root: '../',
},
};
export default nextConfig;
```
Steps to reproduce:
- Set up an npm workspace monorepo with Next.js in a subdirectory
- Install dependencies at workspace root (
npm cifrom root) - Run
next buildfrom within the Next.js package directory (e.g. vianpm run build --workspace=frontend)
Expected behavior
Setting turbopack.root to the workspace root should expand Turbopack's module resolution scope to include the root node_modules, making PostCSS plugins resolvable.
Actual behavior
Build fails with the following error:
```
Error: Turbopack build failed with 1 errors:
./frontend/src/app/globals.css
Error evaluating Node.js code
Error: Cannot find module '@tailwindcss/postcss'
Require stack:
- /app/frontend/.next/build/chunks/[root-of-the-server]__048u7-j._.js
```
The warning ⚠ turbopack.root should be absolute, using: /app confirms the root is resolved correctly to /app, yet the PostCSS child process still cannot find @tailwindcss/postcss at /app/node_modules/@tailwindcss/postcss.
Analysis
It appears that turbopack.root correctly affects Turbopack's main compilation (TS/JS files), but the PostCSS transform — which runs in a separate Node.js child process — does not inherit this scope. The child process module resolution appears to be restricted to the project directory (/app/frontend) rather than the workspace root (/app).
Workaround: Setting NODE_PATH=/app/node_modules as an environment variable before running the build.
Environment
- Next.js version: 16.2.1
- Node.js version: 20 (alpine)
- Package manager: npm workspaces
- OS: Linux (Docker / GitHub Actions)