next.js: [turborepo] [turbopack] Running a NextJs app by using the --turbo flag in the TurboRepo monorepo, causes Error: Next.js package not found

Link to the code that reproduces this issue

https://codesandbox.io/s/focused-newton-8l2xcm

To Reproduce

  1. Fresh install of TurboRepo monorepo
  2. Run the web NextJs app by using the --turbo flag
  3. Open the http://localhost:3000 on your browser
  4. Internal Server Error
  5. Check out the terminal

Current vs. Expected behavior

Dev build and run the project must work but right after npm run dev and opening the browser it falls into the Server error:

Full LOG
Debug info:
- Execution of get_next_package failed
- Next.js package not found
at withErrorCause (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:391:19)
at async EndpointImpl.writeToDisk (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:581:20)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-utils/setup-dev.js:922:79)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-server.js:87:24)
at async DevServer.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:510:9)
at async Object.ensure (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:163:17)
at async DevRouteMatcherManager.matchAll (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/future/route-matcher-managers/dev-route-matcher-manager.js:94:13)
at async DevRouteMatcherManager.match (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/future/route-matcher-managers/default-route-matcher-manager.js:159:26)
at async DevServer.handleCatchallRenderRequest (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/next-server.js:567:27)
at async DevServer.handleRequestImpl (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:728:17) {
[cause]: [Error: Next.js package not found

Debug info:
- Execution of get_next_package failed
- Next.js package not found] {
code: 'GenericFailure'
}
}
Error: expected next/dist/client/next-dev-turbopack.js to resolve to a module

Debug info:
- Execution of PageEndpoint::client_chunks failed
- expected next/dist/client/next-dev-turbopack.js to resolve to a module
at withErrorCause (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:391:19)
at async EndpointImpl.writeToDisk (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:581:20)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-utils/setup-dev.js:790:77)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-server.js:87:24)
at async DevServer.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:510:9)
at async DevServer.findPageComponents (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:526:17)
at async DevServer.renderErrorToResponseImpl (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:1804:26)
at async pipe.req.req (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:1732:30)
at async DevServer.pipeImpl (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:826:25)
at async DevServer.handleCatchallRenderRequest (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/next-server.js:638:17)
at async DevServer.handleRequestImpl (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:728:17) {
[cause]: [Error: expected next/dist/client/next-dev-turbopack.js to resolve to a module

Debug info:
- Execution of PageEndpoint::client_chunks failed
- expected next/dist/client/next-dev-turbopack.js to resolve to a module] {
code: 'GenericFailure'
}
}
Error: Next.js package not found

Debug info:
- Execution of get_next_package failed
- Next.js package not found
at withErrorCause (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:391:19)
at async EndpointImpl.writeToDisk (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:581:20)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-utils/setup-dev.js:922:79)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-server.js:87:24)
at async DevServer.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:510:9)
at async Object.ensure (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:163:17)
at async DevRouteMatcherManager.matchAll (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/future/route-matcher-managers/dev-route-matcher-manager.js:94:13)
at async DevRouteMatcherManager.match (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/future/route-matcher-managers/default-route-matcher-manager.js:159:26)
at async DevServer.handleCatchallRenderRequest (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/next-server.js:567:27)
at async DevServer.handleRequestImpl (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:728:17) {
[cause]: [Error: Next.js package not found

Debug info:
- Execution of get_next_package failed
- Next.js package not found] {
code: 'GenericFailure'
}
}
Error: expected next/dist/client/next-dev-turbopack.js to resolve to a module

Debug info:
- Execution of PageEndpoint::client_chunks failed
- expected next/dist/client/next-dev-turbopack.js to resolve to a module
at withErrorCause (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:391:19)
at async EndpointImpl.writeToDisk (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:581:20)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-utils/setup-dev.js:790:77)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-server.js:87:24)
at async DevServer.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:510:9)
at async DevServer.findPageComponents (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:526:17)
at async DevServer.renderErrorToResponseImpl (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:1804:26)
at async pipe.req.req (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:1732:30)
at async DevServer.pipeImpl (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:826:25) {
[cause]: [Error: expected next/dist/client/next-dev-turbopack.js to resolve to a module

Debug info:
- Execution of PageEndpoint::client_chunks failed
- expected next/dist/client/next-dev-turbopack.js to resolve to a module] {
code: 'GenericFailure'
}
}
Error: expected next/dist/client/next-dev-turbopack.js to resolve to a module

Debug info:
- Execution of PageEndpoint::client_chunks failed
- expected next/dist/client/next-dev-turbopack.js to resolve to a module
at withErrorCause (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:391:19)
at async EndpointImpl.writeToDisk (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:581:20)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-utils/setup-dev.js:790:77)
at async Object.getFallbackErrorComponents (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-server.js:99:17)
at async DevServer.getFallbackErrorComponents (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:553:9)
at async DevServer.renderErrorToResponseImpl (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:1875:40)
at async pipe.req.req (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:1732:30)
at async DevServer.pipeImpl (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:826:25) {
[cause]: [Error: expected next/dist/client/next-dev-turbopack.js to resolve to a module

Debug info:
- Execution of PageEndpoint::client_chunks failed
- expected next/dist/client/next-dev-turbopack.js to resolve to a module] {
code: 'GenericFailure'
}
}
⨯ Error: Next.js package not found

Debug info:
- Execution of get_next_package failed
- Next.js package not found
at withErrorCause (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:391:19)
at async EndpointImpl.writeToDisk (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/build/swc/index.js:581:20)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-utils/setup-dev.js:946:79)
at async Object.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/lib/router-server.js:87:24)
at async DevServer.ensurePage (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:510:9)
at async Object.ensure (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/dev/next-dev-server.js:163:17)
at async DevRouteMatcherManager.matchAll (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/future/route-matcher-managers/dev-route-matcher-manager.js:94:13)
at async DevRouteMatcherManager.match (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/future/route-matcher-managers/default-route-matcher-manager.js:159:26)
at async DevServer.handleCatchallRenderRequest (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/next-server.js:567:27)
at async DevServer.handleRequestImpl (/Users/MacBookPro_ProjectsDirectory/test-next-turborepo/node_modules/next/dist/server/base-server.js:728:17) {
[cause]: [Error: Next.js package not found

Debug info:
- Execution of get_next_package failed
- Next.js package not found] {
code: 'GenericFailure'
}
}

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.5.0
Binaries:
  Node: 18.14.1
  npm: 9.3.1
  Yarn: 1.22.19
Relevant Packages:
  next: 13.4.19
  eslint-config-next: 13.4.20
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2

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

Turbopack (–turbo)

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Reactions: 11
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Same error with pnpm monorepo as well.

Still relevant in Next.js 14.0.1.

It doesn’t work in an Nx monorepo with yarn.

@balazsorban44

Please do the following steps exactly one by one:

  1. Inside your terminal type npx create-turbo@latest
  2. Leave a custom name eg: amer-reproduce
  3. Choose bun (with npm and yarn it works properly)
  4. The monorepo contains the following tree
    apps
      - apps/docs
      - apps/web
    packages
      - packages/eslint-config-custom
      - packages/tsconfig
      - packages/ui
    
    Let’s talk about the web application in the apps folder
  5. Inside the web project open the package.json file and edit the dev script
     "dev": "next dev --turbo"
    
  6. Open your terminal at the web app of the amer-reproduce folder and type the following command:
    bun run dev
    
  7. It will be built by using TUBROPACK and now it’s time to raise up your browser and open the given link:
    http://localhost:3000
    
  8. You will see the Internal Server Error on the browser
  9. You will see the following inside the terminal:
    ⨯ Error: Next.js package not found
    
    Debug info:
    - Execution of get_next_package failed
    - Next.js package not found
    

I still get this error with yarn on next 14.1

Hi, I tried reproducing it, but couldn’t. I see you are on 13.4.19 which is not the latest version. Can you try to update to next@canary or next@latest and report back?