Description
Link to the code that reproduces this issue
https://github.com/taheramr/reproducing-nextjs-txt-404
To Reproduce
- Clone the repo
- Build the application
npx serve out
- Open localhost and keep the dev tools opened
- Observe the network tab and the 404 error
Current vs. Expected behavior
When adding a resource to NextJS in its public directory, this resource can be some other assets built from another package for example and when trying to route to that resource (index.html) NextJS tries to prefetch that resource by appending a .txt
to the resource path which casues a 404.
The expected behavior that nextjs does not prefetch it.
Provide environment information
Happens in pretty much every operating system.
Which area(s) are affected? (Select all that apply)
Not Found, Redirects, Linking and Navigating
Which stage(s) are affected? (Select all that apply)
next build (local), Vercel (Deployed), Other (Deployed)
Additional context
I tested the issue with multiple NextJS versions (14 & 15). This is happening in our own website https://cloudscape.design/demos/, if you clicked on one link on the side navigation it will link you to an html pre-generated page. NextJS creates an additional request with a .txt
and appends it which causes a 404 and overwhelms our reporting tools.