nextjs - 💡(How to fix) Fix monorepo setup [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#88366Fetched 2026-04-08 02:04:56
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×2closed ×1commented ×1issue_type_added ×1

Error Message

then when i run npm run dev turbopack is infers the workspace incorrectly ERROR MESSAGE: Error: Next.js inferred your workspace root, but it may not be correct. npm error Lifecycle script dev failed with error: npm error code 1 npm error path /home/jesse-collins/code-snippets/apps/web npm error workspace @code-snippets/[email protected] npm error location /home/jesse-collins/code-snippets/apps/web npm error command failed npm error command sh -c next dev When running npm run dev --workspace=@code-snippets/web, I get the following error: I was running a single repo however have migrated to a monorepo also was using docker but the issue lies in that I can't even run it locally it should compile in theory and give a different error if there was compile error thanks for all your help!

Code Example

npx next info // note this is from ./apps/web
/bin/sh: 1: yarn: not found
/bin/sh: 1: pnpm: not found

Operating System:
  Platform: linux
  Arch: x64
  Version: #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 20 10:25:38 UTC 2
  Available memory (MB): 31980
  Available CPU cores: 8
Binaries:
  Node: 25.2.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.1.1 // Latest available version is detected (16.1.1).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

private code idc if you close the issue I am unable to provide any form of code today thanks

To Reproduce

next version 16.1.1 running into an issue with a monorepo here is my folder stucture ├── apps/ │ ├── web/ ← Next.js app goes here .next │ │ ├── src/
│ │ ├── public/
│ │ ├── package.json
│ │ ├── next.config.ts
│ │ ├── tsconfig.json
│ │ ├── tailwind.config.ts │ │ ├── postcss.config.mjs │ │ └── components.json
│ │ │ └── worker/ ← Worker app │ ├── src/ │ │ └── index.ts
│ ├── package.json
│ └── tsconfig.json
│ ├── packages/ │ ├── database/ ← Shared database │ │ ├── prisma/ ( │ │ ├── index.ts
│ │ ├── client.ts
│ │ └── package.json
│ │ │ └── queue/ ← Shared queue code │ ├── index.ts
│ ├── types.ts

│ └── package.json
│ ├── package.json
├── tsconfig.base.json
├── compose.yaml
├── .env ├── .gitignore └── README.md

a lot of files removed due to private code the issue arise when i run install, the node_modules correctly appears in the root directory. this is my root package.json { "name": "code-snippets-monorepo", "version": "0.1.0", "private": true, "workspaces": [ "apps/", "packages/"

], "scripts": { "dev": "npm run dev --workspace=apps/web", "dev:worker": "npm run dev --workspace=apps/worker", "build": "npm run build --workspace=apps/web", "build:worker": "npm run build --workspace=apps/worker", "start": "npm run start --workspace=apps/web", "lint": "npm run lint --workspace=apps/web", "test": "npm run test --workspace=apps/web", "testW": "npm run testW --workspace=apps/web", "storybook": "npm run storybook --workspace=apps/web", "build-storybook": "npm run build-storybook --workspace=apps/web", "db:migrate": "npm run db:migrate --workspace=packages/database", "db:generate": "npm run db:generate --workspace=packages/database", "db:studio": "npm run db:studio --workspace=packages/database", "type-check": "npm run type-check --workspace=apps/web" }, "devDependencies": { "typescript": "^5", "tsx": "^4.21.0" } } then when i run npm run dev turbopack is infers the workspace incorrectly ERROR MESSAGE: Error: Next.js inferred your workspace root, but it may not be correct. We couldn't find the Next.js package (next/package.json) from the project directory: /home/jesse-collins/code-snippets/apps/web/app To fix this, set turbopack.root in your Next.js config, or ensure the Next.js package is resolvable from this directory. Note: For security and performance reasons, files outside of the project directory will not be compiled. See https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#root-directory for more information.

at ignore-listed frames

npm error Lifecycle script dev failed with error: npm error code 1 npm error path /home/jesse-collins/code-snippets/apps/web npm error workspace @code-snippets/[email protected] npm error location /home/jesse-collins/code-snippets/apps/web npm error command failed npm error command sh -c next dev I attempted the fixes of clear cache rm -rf node_modules and package.lock.json. Also I obviously have my turbopack.root set I tried turbopack:{ root: path.join(__dirname, ".") }, turbopack:{ root: path.resolve(__dirname, ".") },

turbopack:{
  root:__dirname
},
turbopack:{
  root:'./'
},

Also attempted removing app out of src and having a basic app folder of just a layout and a page all depedencies are correct using react 19 "react": "19.2.0", "react-dom": "19.2.0" and node version 25.2.1

Current vs. Expected behavior

When running npm run dev --workspace=@code-snippets/web, I get the following error:

I expected Turbopack to find my package.jsonapp in my project root at web but it is instead looking in app

Provide environment information

npx next info // note this is from ./apps/web
/bin/sh: 1: yarn: not found
/bin/sh: 1: pnpm: not found

Operating System:
  Platform: linux
  Arch: x64
  Version: #37~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 20 10:25:38 UTC 2
  Available memory (MB): 31980
  Available CPU cores: 8
Binaries:
  Node: 25.2.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 16.1.1 // Latest available version is detected (16.1.1).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Turbopack

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

I was running a single repo however have migrated to a monorepo also was using docker but the issue lies in that I can't even run it locally it should compile in theory and give a different error if there was compile error thanks for all your help!

extent analysis

TL;DR

The most likely fix is to correctly configure the turbopack.root in the Next.js config to point to the correct workspace root.

Guidance

  • Verify that the turbopack.root is set correctly in the next.config.ts file, considering the monorepo structure and the workspace root.
  • Check the next.config.ts file for any other configurations that might be affecting the Turbopack setup, such as experimental, concurrentFeatures, or swc configurations.
  • Ensure that the package.json file in the workspace root (/home/jesse-collins/code-snippets/apps/web) is correctly configured and has the necessary dependencies.
  • Try setting turbopack.root to an absolute path, such as path.resolve(__dirname, '../../'), to see if it resolves the issue.

Example

// next.config.ts
module.exports = {
  // ... other configurations ...
  turbopack: {
    root: path.resolve(__dirname, '../../'), // adjust the path according to your monorepo structure
  },
}

Notes

The issue seems to be related to the monorepo structure and the Turbopack configuration. The error message suggests that Turbopack is inferring the workspace root incorrectly. The provided turbopack.root configurations may not be correct, and further investigation is needed to determine the correct configuration.

Recommendation

Apply a workaround by setting the turbopack.root to an absolute path, as mentioned in the guidance section, to see if it resolves the issue. If the problem persists, further debugging and investigation may be required to determine the root cause.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix monorepo setup [1 comments, 2 participants]