nextjs - 💡(How to fix) Fix Turbopack fails to resolve local package, works with webpack [7 comments, 4 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#85057Fetched 2026-04-08 02:17:34
View on GitHub
Comments
7
Participants
4
Timeline
26
Reactions
1
Timeline (top)
subscribed ×8commented ×7mentioned ×5labeled ×2

Error Message

error: script "dev:turbopack" exited with code 1

Code Example

Module not found: Can't resolve 'lib'

---

next/
  src/app/page.tsx   --> imports from "lib"
  package.json        --> has dependency on "lib" (e.g., file:../lib or link)

lib/
  package.json        --> "name": "lib"

---

bun link
   bun install

---

bun install

---

bun run dev:turbopack
   # ❌ observe error

---

bun run dev
   # ✅ works as expected

---

Module not found: Can't resolve 'lib'

---

import { libNumber } from "lib";

---

error: script "dev:turbopack" exited with code 1

---

import { libNumber } from "lib";

---

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Education
  Available memory (MB): 31896
  Available CPU cores: 16
Binaries:
  Node: 22.14.0
  npm: 10.8.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.5.6 // Latest available version is detected (15.5.6).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/rubenferreira97/turbopack_issue

To Reproduce

🧩 Summary

Importing a local package named lib from a Next.js app fails only under Turbopack with:

Module not found: Can't resolve 'lib'

The same setup works with the default (webpack) dev server.


⚙️ Reproduction

Structure

next/
  src/app/page.tsx   --> imports from "lib"
  package.json        --> has dependency on "lib" (e.g., file:../lib or link)

lib/
  package.json        --> "name": "lib"

Steps to reproduce

Note: Uses the link: protocol. This is supported by bun. If using npm, prefer file:../lib.

  1. In lib:

    bun link
    bun install
  2. In next:

    bun install
  3. Run with Turbopack:

    bun run dev:turbopack
    # ❌ observe error
  4. Run with webpack:

    bun run dev
    # ✅ works as expected

🧠 Error

From ./src/app/page.tsx:1:

Module not found: Can't resolve 'lib'

Code:

import { libNumber } from "lib";

Full message: https://nextjs.org/docs/messages/module-not-found

error: script "dev:turbopack" exited with code 1

🧩 Additional Context

The issue appears specific to Turbopack’s module resolution for local / workspace / file-based dependencies imported by package name.

Current vs. Expected behavior

✅ Expected Behavior

Turbopack should resolve the local package lib the same way webpack does, allowing:

import { libNumber } from "lib";

to work as expected.


❌ Actual Behavior

Turbopack fails to resolve the bare specifier 'lib', while webpack resolves it correctly and the app runs without issues.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Education
  Available memory (MB): 31896
  Available CPU cores: 16
Binaries:
  Node: 22.14.0
  npm: 10.8.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.5.6 // Latest available version is detected (15.5.6).
  eslint-config-next: N/A
  react: 19.1.0
  react-dom: 19.1.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), next build (local), next start (local)

Additional context

No response

extent analysis

TL;DR

The issue can likely be resolved by configuring Turbopack to properly resolve local package dependencies.

Guidance

  • Verify that the lib package is correctly linked and installed in the next project by checking the node_modules directory.
  • Check the Turbopack configuration to ensure it is set up to resolve local packages correctly, potentially by adding a custom resolver.
  • Try using a relative import path instead of the package name, e.g., import { libNumber } from '../lib';.
  • Review the bun.link and bun.install commands to ensure they are correctly setting up the local package dependency.

Example

No specific code example is provided, as the issue seems to be related to the configuration and setup of Turbopack and local package dependencies.

Notes

The issue appears to be specific to Turbopack's module resolution for local packages, and the provided information suggests that the setup works correctly with the default webpack dev server. Further investigation into Turbopack's configuration and documentation may be necessary to resolve the issue.

Recommendation

Apply a workaround by using a relative import path or configuring Turbopack to properly resolve local package dependencies, as the root cause of the issue seems to be related to Turbopack's module resolution.

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