Skip to content

Turbopack fails to resolve paths outside the next app in a monorepo. #79335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
satvik-1203 opened this issue May 17, 2025 · 1 comment
Closed
Labels
Module Resolution Module resolution (CJS / ESM, module resolving).

Comments

@satvik-1203
Copy link

Link to the code that reproduces this issue

https://github.com/satvik-1203/turbopack-path-issues

To Reproduce

Start by going into next-app.
Install all packages in common-ts and next-app.
Run npm run dev to run it without turbopack and on port 3000
Run npm run dev:turbo to run it with turbopack and on port 3001.

It works fine while using Webpack. However, it has trouble importing from common-ts. Path.alias fails, too, in Turbo Pack.

Current vs. Expected behavior

Current behaviour: Module not found: Can't resolve '@common-ts/mock'
Expected behavior: should import the file from @common-ts/mock and work in the next app.

Path alias configured properly in tsconfig.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Fri Jul  5 17:56:15 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T6031
  Available memory (MB): 36864
  Available CPU cores: 14
Binaries:
  Node: 22.15.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: 9.12.0
Relevant Packages:
  next: 15.3.2 // Latest available version is detected (15.3.2).
  eslint-config-next: 15.3.2
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: N/A

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

Module Resolution

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

next dev (local)

Additional context

No response

@github-actions github-actions bot added the Module Resolution Module resolution (CJS / ESM, module resolving). label May 17, 2025
@satvik-1203 satvik-1203 changed the title Turbopack fails to resolve absolute paths outside the main repo. Turbopack fails to resolve paths outside the main repo. May 17, 2025
@satvik-1203 satvik-1203 changed the title Turbopack fails to resolve paths outside the main repo. Turbopack fails to resolve paths outside the next app. May 17, 2025
@satvik-1203 satvik-1203 changed the title Turbopack fails to resolve paths outside the next app. Turbopack fails to resolve paths outside the next app in a monorepo. May 17, 2025
@timneutkens
Copy link
Member

You didn't set up a monorepo, that's why it doesn't work automatically. This is a git repository with 2 folders that hold their own application with their own dependencies and their own lockfiles.

During bootup of Next.js the root of the application is decided, for which we look for e.g. package-lock.json yarn.lock and such. Since in this case next-app has a lockfile it will use next-app as the root. Not the parent above it, as that is just a folder.

When setting up e.g. npm/pnpm/yarn workspaces that would correctly automatically detect the root of the application.

If you don't want to set up workspaces you can also provide the turbopack.root option: https://nextjs.org/docs/app/api-reference/config/next-config-js/turbopack#root-directory with the directory. However not having workspaces but still importing code outside of the workspace will cause a lot of duplication as dependencies wouldn't be deduped by your package manager.

This is both a security and correctness feature, as you wouldn't want e.g. your private key in the user root to be able to be bundled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module Resolution Module resolution (CJS / ESM, module resolving).
Projects
None yet
Development

No branches or pull requests

2 participants