Skip to content

using Pages Router with basePath set in next.config.js results in 404 error when making <basePath>/_next/data/<BUILD_ID>/<path>.json requests #897

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

Open
chiakaiming opened this issue Jun 10, 2025 · 0 comments

Comments

@chiakaiming
Copy link

chiakaiming commented Jun 10, 2025

Hello!

I'm consistently facing a 404 error on <basePath>/_next/data/<BUILD_ID>/<path>.json requests.

The issue arises when providing a value for basePath in next.config.js (tested on a project using pages router).

Looking at the matchRoute function in packages/open-next/src/core/routing/routeMatcher.ts, the regex array used to match a path is derived from optionalBasepathPrefixRegex which prepends the basePath to the path regex. This results is a regex pattern that looks something this:

/^\/basePath\/?(?:)?path(?:\/)?$/

In the function fixDataPage in packages/open-next/src/core/routing/matcher.ts, we are removing the dataPattern (<basePath>/_next/data/<BUILD_ID>) from rawPath which includes the basePath resulting in a transformed rawPath of just /path.

When matchRoute is eventually called, it will try to match the above regex pattern with /path which will fail, resulting in a 404 response return for the data route.

When newPath is initialised in fixDataPage, can we prepend it with ${NextConfig.basePath ?? ""} so that the transformed rawPath would be basePath/path?

Thank you!

PS: Currently, when handling a route, fixDataPage outputs /path for both .../basePath/.../path and .../path requests which I don't think is the intended behaviour?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant