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

Monorepo symlinked dependencies not being externalized #27722

Closed
bgoyarts opened this issue Aug 3, 2021 · 3 comments
Closed

Monorepo symlinked dependencies not being externalized #27722

bgoyarts opened this issue Aug 3, 2021 · 3 comments
Labels
bug Issue was opened via the bug report template. please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity

Comments

@bgoyarts
Copy link

bgoyarts commented Aug 3, 2021

What version of Next.js are you using?

10.0.6

What version of Node.js are you using?

14.17.3

What browser are you using?

Firefox

What operating system are you using?

Ubuntu

How are you deploying your application?

other

Describe the Bug

The following pr #19518 which was released for version 10.0.6 has introduced an issue for us. We are using a monorepo setup which includes a nextjs site. Our folder structure looks as follows:

project
|
|--packages
|  |
|  |-package-a
|  |
|  |-package-b
|
|--nextjs-site

We use lerna in combination with yarn workspaces to hoist the dependencies to the root node_modules folder. However, since the introduction of the above pr, require.resolve returns the destination path of the symlink.
This means when loading the dependencies, the path is seen as /home/user/project/packages/package-a/index.js as opposed to /home/user/project/node_modules/package-a/index.js.

This is problematic because on the following line we check the path for the existence of node_modules https://github.com/vercel/next.js/blob/v10.0.6/packages/next/build/webpack-config.ts#L695 .
Since it cannot find node_modules in the path the dependencies are inlined. As most of our code is contained in the different packages, the output in .next/server/pages has increased to a point we get out of memory errors during development mode.

Expected Behavior

I would expect the hoisted and symlinked dependencies to be externalized.

To Reproduce

I have created a reproduction repository here. To test, check out the repo, install the dependencies and run yarn dev inside the my-app folder. You can see the output in .next/server/pages/index.js, the dependencies are inlined in the output.

To compare the output before the introduction of this issue, set the dependency of next in my-app/package.json to 10.0.5. You will see that the dependencies are externalized as expected.

Edit:

To make it easier to see the issue, without checking out the above repoistory, I have created a diff between the two versions and included the build output. Here you can see the compare bgoyarts/next-reproduction@nextjs-v10.0.5...nextjs-v10.0.6

@bgoyarts bgoyarts added the bug Issue was opened via the bug report template. label Aug 3, 2021
@bgoyarts bgoyarts changed the title Monorepo symlinked dependencies not being inlined in pages Monorepo symlinked dependencies not being externalized Aug 3, 2021
@jankaifer
Copy link
Contributor

Is anyone still facing this in next@canary?

@jankaifer jankaifer added the please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity label Nov 29, 2022
@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.

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. 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 Jan 31, 2023
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. please verify canary The issue should be verified against next@canary. It will be closed after 30 days of inactivity
Projects
None yet
Development

No branches or pull requests

3 participants