Skip to content
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

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

Closed
1 task done
amerllica opened this issue Oct 16, 2023 · 15 comments
Labels
bug Issue was opened via the bug report template. locked please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity Turbopack Related to Turbopack with Next.js.

Comments

@amerllica
Copy link

amerllica commented Oct 16, 2023

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

@amerllica amerllica added the bug Issue was opened via the bug report template. label Oct 16, 2023
@github-actions github-actions bot added the Turbopack Related to Turbopack with Next.js. label Oct 16, 2023
@balazsorban44
Copy link
Member

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?

@balazsorban44 balazsorban44 added the please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity label Oct 16, 2023
@github-actions
Copy link
Contributor

Please verify that your issue can be recreated with next@canary.

Why was this issue marked with the please verify canary label?

We noticed the provided reproduction was using an older version of Next.js, instead of canary.

The canary version of Next.js ships daily and includes all features and fixes that have not been released to the stable version yet. You can think of canary as a public beta. Some issues may already be fixed in the canary version, so please verify that your issue reproduces by running npm install next@canary and test it in your project, using your reproduction steps.

If the issue does not reproduce with the canary version, then it has already been fixed and this issue can be closed.

How can I quickly verify if my issue has been fixed in canary?

The safest way is to install next@canary in your project and test it, but you can also search through closed Next.js issues for duplicates or check the Next.js releases. You can also use the GitHub templates (preferred) for App Router and Pages Router, or the CodeSandbox: App Router or CodeSandbox: Pages Router templates to create a reproduction with canary from scratch.

My issue has been open for a long time, why do I need to verify canary now?

Next.js does not backport bug fixes to older versions of Next.js. Instead, we are trying to introduce only a minimal amount of breaking changes between major releases.

What happens if I don't verify against the canary version of Next.js?

An issue with the please verify canary that receives no meaningful activity (e.g. new comments that acknowledge verification against canary) will be automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue, with the required reproduction, using next@canary.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren't you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

@amerllica
Copy link
Author

@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
    

@wescopeland
Copy link

Still relevant in Next.js 14.0.1.

@amerllica
Copy link
Author

Yes @wescopeland, With yarn it works but with bun doesn't

@wescopeland
Copy link

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

@Arctomachine
Copy link

Same error with pnpm monorepo as well.

@abhinaypandey02
Copy link
Contributor

I deleted my package-lock.json and node_modules that was inside my app and it worked. (You will have package-lock if you added a new app using create-next-app).

I was using pnpm and next@14

@Ahn1
Copy link

Ahn1 commented Nov 26, 2023

I had the same problem, but I was able to get it running by settings the tracing root to the root of my monorepo:

In the next.config.js set:

module.exports = {
  experimental: {
    outputFileTracingRoot: path.join(__dirname, "../../"),
  },
 [...]
}

But maybe consider to do it only in development env, because it alters the output of the next build command:

module.exports = {
  experimental: {
    ...(process.env.NODE_ENV === "development"
      ? { outputFileTracingRoot: path.join(__dirname, "../") }
      : null),
  },
 [...]
}

It works perfectly for me on a pnpm monorepo.

@gaboesquivel
Copy link

Thanks! @Ahn1, I can confirm this works with npm

image

@rushi3691
Copy link

  1. You will see the Internal Server Error on the browser
  2. 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
    

getting same error with bun and --turbo. Is there any workaround for it?

@balazsorban44
Copy link
Member

This issue has been automatically closed because it wasn't verified against next@canary. If you think it was closed by accident, please leave a comment. If you are running into a similar issue, please open a new issue with a reproduction. Thank you.

@Arctomachine

This comment has been minimized.

@SoerenSilkjaer
Copy link

I still get this error with yarn on next 14.1

Copy link
Contributor

github-actions bot commented Feb 6, 2024

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 added the locked label Feb 6, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity Turbopack Related to Turbopack with Next.js.
Projects
None yet
Development

No branches or pull requests

9 participants