Skip to content

turbopack.root does not apply to PostCSS child process module resolution in npm workspace setup #92060

@jun-eg

Description

@jun-eg

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:

  1. Set up an npm workspace monorepo with Next.js in a subdirectory
  2. Install dependencies at workspace root (npm ci from root)
  3. Run next build from within the Next.js package directory (e.g. via npm 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalid linkThe issue was auto-closed due to a missing/invalid reproduction link. A new issue should be opened.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions