-
SummaryI am creating a directory outside of the project, let's call it I've tried to trace the code and it seems to be resolving the symlinks correctly in the I've created a minimal reproduction of the issue and linked the repo to this discussion. Steps to reproduce:
Observe the following: If you remove the symlink and paste the vendor files directly into the Link to repo with reproduction. Additional informationNo response Examplehttps://github.com/snivels/symlinks-not-working |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It seems like watchpack is the issue, it's using Next.js itself has correct support for symlinks. If anyone wants to use symlinks in their project, you can change the calls from
Then use patch-package to create a patch for your version of Next.js: npx patch-package next And then update your Closing the discussion with a resolution in case anyone wants a temporary solution until watchpack updates this. Also updated the reproduction branch to now include the patch. |
Beta Was this translation helpful? Give feedback.
-
The scope of this bug is relatively small: You can symlink files and non-route directories, just not route directories. The bug is in the development server's route manifest generation. I don't have the time to prioritize and fix this myself, but hopefully this helps explain things if somebody does want to try to fix it. I looked into this. Unfortunately, a proper fix would be a lot more complicated than modifying watchpack:
Watchpack has a
if you watch
If you use
However, it won't watch the contents of We can simplify things a bit by not allowing symlinks for route directories that point outside of the watched project directory/repository, but a proper solution would still be rather complicated:
If fixed, this may reveal other issues with directory traversal in other parts of Next.js. |
Beta Was this translation helpful? Give feedback.
It seems like watchpack is the issue, it's using
fs.lstat
instead offs.stat
and is not recognizing symlinks.Next.js itself has correct support for symlinks.
If anyone wants to use symlinks in their project, you can change the calls from
.lstat(
to.stat(
in the following file:Then use patch-package to create a patch for your version of Next.js:
And then update your
postinstall
to patch packages after install:Closing the discussion with a resolution in case anyone wants a temporary solution until watchpack updates this.
Also updated the reproduction branch to now include the patch.