Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Turbopack fails to resolve symbolically linked modules outside project directory #77562

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
dimak-dev opened this issue Mar 27, 2025 · 3 comments
Labels
locked Turbopack Related to Turbopack with Next.js.

Comments

@dimak-dev
Copy link

Link to the code that reproduces this issue

https://github.com/dimak-dev/turbopack-local-module-symlink-bug

To Reproduce

  1. Create a new Next.js project:

    npx create-next-app@latest  
  2. Create or download an external module in a separate directory:

    npm init 
  3. Add an exportable function to this module:

    export function foo() {
      return 'bar';
    }
  4. Install the external module into the Next.js project as a symlink (not a hard copy):

    npm install <path_to_external_module> 
  5. Import the foo() function into the Next.js project.

  6. Run the Next.js development server with Turbopack enabled:

    next dev --turbo

OR

  1. Clone this repository:
    git clone https://github.com/dimak-dev/turbopack-local-module-symlink-bug.git
    cd turbopack-local-module-symlink-bug
  2. Navigate to the next.js directory:
    cd next.js
  3. Start the Next.js development server using Turbopack:
    npm run dev:turbo
  4. Observe the error indicating that Turbopack cannot resolve the internal-module (Build Error: Module not found: Can't resolve 'internal-module').

Current vs. Expected behavior

Expected Behavior: Turbopack should correctly resolve modules linked via symbolic links, even if those modules reside outside the project directory.

Current Behavior: Turbopack throws an error when attempting to resolve the internal-module if it is located outside the project directory.

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:22:00 PST 2025; root:xnu-11215.81.4~3/RELEASE_X86_64
  Available memory (MB): 16384
  Available CPU cores: 12
Binaries:
  Node: 22.13.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.2.4 // Latest available version is detected (15.2.4).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.8.2
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

If the internal-module is located inside the project directory and also uses a symbolic link, the module is resolved correctly without errors.

Canary (15.3.0-canary.24) is also affected.

@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label Mar 27, 2025
@Julian-AT
Copy link

Julian-AT commented Mar 27, 2025

bump. Turbopack fails to import certain deps from node_modules (15.2.4)

@timneutkens
Copy link
Member

This is expected because Turbopack will guard against importing files outside of the context of the project.
Next.js automatically detects the project root by finding the pnpm lock / npm lock / bun lock file and uses that folder as the project root. In your case there is no root lockfile so the project root is the next.js directory in the application. In that case you can set experimental.turbo.root:

import type { NextConfig } from "next";
import { join } from "path";

const nextConfig: NextConfig = {
  /* config options here */
  experimental: {
    turbo: {
      root: join(__dirname, ".."),
    },
  },
};

export default nextConfig;

Note that in 15.3 (launching this week) that option will be moved to stable to this:

import type { NextConfig } from "next";
import { join } from "path";

const nextConfig: NextConfig = {
  /* config options here */
  turbopack: {
    root: join(__dirname, ".."),
  },
};

export default nextConfig;

Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

3 participants