next.js: Routing error in dev mode: TypeError: Cannot read property 'includes' of undefined
Bug report
Describe the bug
Beginning in Next.js v9.5.3, clicking on any internal link while running in development mode causes an error (shown below) which prevents the navigation from happening. It works fine in v9.5.2.
To Reproduce
I do not have a minimal reproduction example, but it is occurring in our private repo. Rolling back to v9.5.2 fixes the issue.
- Launch dev server
- Load any URL
- Click any internal link
Unhandled Runtime Error
TypeError: Cannot read property 'includes' of undefined
Call Stack
Router._resolveHref
webpack-internal:///./node_modules/next/dist/next-server/lib/router/router.js (911:18)
Router._callee$
webpack-internal:///./node_modules/next/dist/next-server/lib/router/router.js (441:31)
tryCatch
webpack-internal:///./node_modules/regenerator-runtime/runtime.js (63:40)
Generator.invoke [as _invoke]
webpack-internal:///./node_modules/regenerator-runtime/runtime.js (293:22)
Generator.eval [as next]
webpack-internal:///./node_modules/regenerator-runtime/runtime.js (118:21)
asyncGeneratorStep
webpack-internal:///./node_modules/next/node_modules/@babel/runtime/helpers/asyncToGenerator.js (3:24)
_next
webpack-internal:///./node_modules/next/node_modules/@babel/runtime/helpers/asyncToGenerator.js (25:9)
Expected behavior
Expect browser to navigate to new href location.
Instead, it displays the error above and does not redirect.
Screenshots
System information
- OS: MacOS 10.15.6
- Browser: Brave Version 1.12.114 Chromium: 84.0.4147.135 (Official Build) (64-bit)
- Version of Next.js: 9.5.3
- Version of Node.js: 14.9.0
Additional context
We have a custom server, custom next.config.js and custom webpack configuration, but all seems to work fine in v9.5.2 and below. Also, this issue does not occur in production mode - only development mode.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 41
- Comments: 40 (13 by maintainers)
@haluvibe If you add
this.passthrough('/_next/static/development/_devPagesManifest.json');to the top of yourroutes()function inmirage.jsthat should solve the problem.Just a quick note, if you’re using a namespace, you should use this solution instead:
Having the same issue, everything works fine and after a few hot reload or manual page reloads, the app loads forever.
In the dev tools I can see that is fetches
_devPagesManifest.jsonforever without a respone.The only solution is the reload the whole app every time. When doing that I sometimes see the error
TypeError: Cannot read property 'includes' of undefinedon the page.any news on this very very annoying bug ?
I was able to replicate the same issue using one of nextjs examples (blog guide). Steps:
Please reset namespace
this.namespace=""before passthrough. Example attached. Restart next server and try.It work’s fine since I’m proxying it to the node server like this:
This is how it looks in my local dev env (based on devilbox docker)
My Next.js app runs outside of the docker at port
3000Any solution?
Here is my test case:
Worked fine on 9.3, the team updated to 9.5, and it’s not working.
The issue is related to @felixmosh’s comment. I can see my request to
/_next/static/development/_devPagesManifest.json404’ing because our setup has Nginx setup to serve files from the filesystem from/_next/staticbut Nextjs doesn’t write that file to disk in development. I added a rule to my local nginx configuration to proxypass that particular route and the issue is resolved. Seems a bit odd to me that Next.js would serve a dynamic file from a static path. Perhaps this should be served under the/_next/datapath?@aleyrizvi , thanks that works perfectly.
I’ve installed miragejs and that has same error.
I’m getting this error after upgrading to React 17.0.02 and next 12.0.1 when I use
<Link><a>...</a></Link>. The errors go away when I remove the<Link>, which is fromnext/link. But I need theLink, so I’m trying to figure out why this is happening.Why would
pagesbe null?If I do a null check on
pagesin that router file, the error stops being thrown. However, when I click the<Link>on the page, I get this error:Why is pageLoader broken, not doing its job?
Happens to our project too, no idea how to repro aside from hitting refresh on the browser a bunch of times. Took a screenshot of the error, maybe it helps.
@abstractvector thanks for that!
So what i did was pull in the standard next request handler as well as next-routes. next-routes deals with all the page routing, then i used the standard handler from
next().getRequestHandler// inside createApp
did the trick. Not sure how / if this would refactor nicely into next-routes. But bringing the default handler in for this file did solve it
Thanks to @mAAdhaTTah I have been able to find a workaround for this. The issue is that the path
/_next/static/development/_devPagesManifest.jsonis requested in development mode, yet the file doesn’t exist - it is generated at runtime.The custom routing was serving static files directly from disk, and assumes that anything in
/_next/static/is, well, static - and hence exists on disk. That has been true up to and including version 9.5.2.The workaround is to bypass our static file serving for that URL. In my case (using
KoaRouter), the easiest solution was to define an explicit route for this URL before my static file routes:While this is a workaround, I’m loathe to close the issue since I agree with @mAAdhaTTah that this URL should probably not be served from
/_next/static, but could be moved to something like/_next/dataor similar.