-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Symlinked app pages fail to resolve in DEV but not PRODUCTION #53175
Comments
Problem IdentifiedIt looks like we're using Viable SolutionsI was able to make a variety of alterations to both watchpack and next.js's code and was able to arrive at a working solution to this problem. The following potential solutions to this issue are detailed below. Each one has differing levels of complexity and impact on next.js and watchpack itself. Additionally, all of the following will require the following changes to: server/future/route-matcher-providers/dev/helpers/file-reader/default-file-reader.ts: - 45: if (file.isDirectory()) {
+ 45: if (file.isDirectory() || file.isSymbolicLink()) { A. Fix in WatchpackWe can swap over watchpack's usage of B. Patching Watchpack's
|
For those of you still looking for a solution, I have a temporary workaround. I was able to use PNPM Patches to make 4 small edits to next.js and watchpack to get things working. See more details in my Repo (specifically the |
This patch is compatible also with version 13.5 of Next.js. However, for version 13.5, you only need to apply the patch to watchpack, as Next.js has updated its directory parsing logic to support symlinks. |
created an issue for tracking webpack/watchpack#231, watchpack resolve the symlinks to the final target looks to be the main root cause. Specifically if the symlink target is outside of the If a change is accepted in watchpack it would likely require a small patch in NextJs to opt-in to the new symlink resolving here:
An alternative direction would be for NextJs to expose a configuration option that would allow user to specify alternative
|
I just did some testing on Next.js 14.1.0 and this issue is still present and even more difficult to address now. Next.js 14.0.0 migrated the The solution to this problem is still just changing Although I appreciate @bartvandenende-wm's attempt to resolve this within watchpack, watchpack has not been updated in 2 years and its README explicitly states:
I think its safe to assume that addressing this issue for Next.js within Watchpack itself goes against the objectives of Watchpack and thus will never get merged in. It must be addressed within Next.js directly. Given that it is possible via running in production, I think we should migrate Next.js's use of Watchpack hot reload using a different implementation; potentially even just a fork of Watchpack with the required modifications. If a maintainer could help weigh in on this, I would greatly appreciate it. Is there any reason why symlinked app directories shouldn't be a feature of Next.js? If next build is working as intended with functioning symlinks, then I think we need to address this issue within the dev server. |
I tried with |
Hello @cseitz , Did you manage to get a work around on this issue? |
Would love to see a resolution to this issue - I'm looking to use symlinked pages to allow external "modules" to define their own routing inside the site without resorting to copying files. Symlinked components from external directories work perfectly fine with the proper configuration, but symlinked routes still don't. |
For anyone looking for a workaround, I use |
I solved this by using |
Verify canary release
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023 Binaries: Node: 18.12.1 npm: 9.7.1 Yarn: 1.22.18 pnpm: 8.6.6 Relevant Packages: next: 13.4.13-canary.1 eslint-config-next: 13.4.12 react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.6 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
App Router, Routing (next/router, next/navigation, next/link), SWC transpilation
Link to the code that reproduces this issue or a replay of the bug
https://github.com/cseitz/next-13.4.13-bug-symlinked-app-dir/
To Reproduce
Running
next dev
and visitinglocalhost:3000/test1
will404 NOT FOUND
.However, running
next build
andnext start
and visitinglocalhost:3000/test1
will work just fine.(Additional details in the README of my repo)
Describe the Bug
I am using a symlinked directory within my
app
folder. This symlink route 404's in development, but works perfectly in production.src/features/test1/app
, that is symlinked intosrc/app/(features)/(test1)
ln -sr "./src/features/test1/app" "./src/app/(features)/(test1)"
next dev
and visitinglocalhost:3000/test1
will404 NOT FOUND
Expected Behavior
When running via
next dev
:localhost:3000/test1
should rendersrc/features/test1/app/test1/page.tsx
, which is located within the symlinked foldernext dev
mirrors the behavior ofnext build && next start
(which is proven to support this symlink feature as it works in production)Which browser are you using? (if relevant)
Chrome 114.0.5735.199
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: