Monorepo symlinked dependencies not being externalized #27722
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
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:
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 themy-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
inmy-app/package.json
to10.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
The text was updated successfully, but these errors were encountered: