This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext main vs Next.js v16.2.6, 2026-05-20).
Problem
When basePath is configured in next.config.js, vinext does not properly enforce path scoping. Multiple sub-issues:
-
Routes/rewrites/redirects fire without the basePath prefix. A rewrite with default basePath: true should only match paths prefixed with the basePath (e.g., /docs). vinext matches them without the prefix, so requesting /rewrite-1 returns 200 instead of 404.
-
basePath: false external rewrites not implemented. Rewrites pointing to external URLs (https://example.com) with basePath: false should proxy the external content. vinext matches the [slug] dynamic route instead.
-
Static assets under basePath return 404. Fetching [basePath]/_next/static/... returns 404 because the static asset layer doesn't account for the basePath prefix.
-
basePath double-applied in asset URLs. HTML output contains /docs/docs/_next/static/... instead of /docs/_next/static/..., indicating the basePath is applied twice.
-
Routes outside basePath not properly rejected. Requesting /hello directly (without /docs prefix) should 404 when basePath: '/docs', but vinext serves the page.
Expected: 404
Received: 200 // for /rewrite-1 without basePath prefix
Expected: "Example Domain"
Received: "...<p id=\"slug\">slug: rewrite-no-basePath</p>..."
Expected: 200
Received: 404 // for /docs/_next/static/...
Estimated Impact
~43 test failures across the deploy suite.
Affected Test Suites
test/e2e/basepath/query-hash.test.ts (10 failures)
test/e2e/basepath/error-pages.test.ts (6 failures)
test/e2e/app-dir/app-basepath/index.test.ts (5 failures)
test/e2e/basepath/redirect-and-rewrite.test.ts (4 failures)
test/e2e/basepath/router-events.test.ts (4 failures)
test/e2e/invalid-static-asset-404-pages/*-base-path.test.ts (3 failures)
test/e2e/invalid-static-asset-404-app/*-base-path.test.ts (2 failures)
test/e2e/i18n-ignore-redirect-source-locale/redirects-with-basepath.test.ts (4 failures)
test/e2e/next-form/basepath/next-form-basepath.test.ts (1 failure)
Recommendation
-
Reproduce first in vinext's own test suite. Add tests that configure basePath: '/docs' and verify: (a) routes without the prefix return 404, (b) rewrites/redirects only match with the prefix, (c) static assets serve correctly under the prefix. Confirm they fail.
-
Study Next.js basePath implementation. Search .nextjs-ref/packages/next/src/server/ for basePath to understand how it gates request handling.
-
Gate rewrites/redirects on basePath. When evaluating next.config.js rewrites and redirects, prepend the basePath to source patterns (unless basePath: false is set on the rule).
-
Fix static asset serving. Strip the basePath prefix before looking up assets in the _next/static directory.
-
Fix asset URL generation. Ensure the basePath is applied exactly once when generating <script> and <link> URLs in HTML output.
-
Implement external URL proxying. For rewrites with basePath: false pointing to absolute URLs, proxy the request to the external origin.
Problem
When
basePathis configured innext.config.js, vinext does not properly enforce path scoping. Multiple sub-issues:Routes/rewrites/redirects fire without the basePath prefix. A rewrite with default
basePath: trueshould only match paths prefixed with the basePath (e.g.,/docs). vinext matches them without the prefix, so requesting/rewrite-1returns 200 instead of 404.basePath: falseexternal rewrites not implemented. Rewrites pointing to external URLs (https://example.com) withbasePath: falseshould proxy the external content. vinext matches the[slug]dynamic route instead.Static assets under basePath return 404. Fetching
[basePath]/_next/static/...returns 404 because the static asset layer doesn't account for the basePath prefix.basePath double-applied in asset URLs. HTML output contains
/docs/docs/_next/static/...instead of/docs/_next/static/..., indicating the basePath is applied twice.Routes outside basePath not properly rejected. Requesting
/hellodirectly (without/docsprefix) should 404 whenbasePath: '/docs', but vinext serves the page.Estimated Impact
~43 test failures across the deploy suite.
Affected Test Suites
test/e2e/basepath/query-hash.test.ts(10 failures)test/e2e/basepath/error-pages.test.ts(6 failures)test/e2e/app-dir/app-basepath/index.test.ts(5 failures)test/e2e/basepath/redirect-and-rewrite.test.ts(4 failures)test/e2e/basepath/router-events.test.ts(4 failures)test/e2e/invalid-static-asset-404-pages/*-base-path.test.ts(3 failures)test/e2e/invalid-static-asset-404-app/*-base-path.test.ts(2 failures)test/e2e/i18n-ignore-redirect-source-locale/redirects-with-basepath.test.ts(4 failures)test/e2e/next-form/basepath/next-form-basepath.test.ts(1 failure)Recommendation
Reproduce first in vinext's own test suite. Add tests that configure
basePath: '/docs'and verify: (a) routes without the prefix return 404, (b) rewrites/redirects only match with the prefix, (c) static assets serve correctly under the prefix. Confirm they fail.Study Next.js basePath implementation. Search
.nextjs-ref/packages/next/src/server/forbasePathto understand how it gates request handling.Gate rewrites/redirects on basePath. When evaluating
next.config.jsrewrites and redirects, prepend the basePath to source patterns (unlessbasePath: falseis set on the rule).Fix static asset serving. Strip the basePath prefix before looking up assets in the
_next/staticdirectory.Fix asset URL generation. Ensure the basePath is applied exactly once when generating
<script>and<link>URLs in HTML output.Implement external URL proxying. For rewrites with
basePath: falsepointing to absolute URLs, proxy the request to the external origin.