Skip to content
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

Cannot rewrite to external URL when basePath option is defined in next.config.js contains a hyphen #74431

Open
massaynus opened this issue Dec 31, 2024 · 5 comments
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc. Internationalization (i18n) Related to Internationalization with Next.js. Middleware Related to Next.js Middleware. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@massaynus
Copy link

Link to the code that reproduces this issue

https://github.com/massaynus/next-rewrite-issue

To Reproduce

  1. start app in dev mode
  2. open network tab in dev tools and access the app in http://localhost:3000/mj-builder
  3. notice how the rewrite which has the app basePath and locale in it fails to execute the rewrite even if the url is computed correctly

Current vs. Expected behavior

if the basePath in next.config.mjs is set to /app for example it works fine, it should be the same for basePaths with a hyphen in them like the value mj-builder showin in the example repo

Provide environment information

/bin/sh: 1: yarn: not found
/bin/sh: 1: pnpm: not found

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
  Available memory (MB): 31943
  Available CPU cores: 20
Binaries:
  Node: 20.17.0
  npm: 11.0.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.1.3 // Latest available version is detected (15.1.3).
  eslint-config-next: 15.1.0
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.7.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Developer Experience, Internationalization (i18n), Middleware, Runtime

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), next start (local), Other (Deployed)

Additional context

first discovered the issue on v15.1.0 then tested on v15.1.3 and also canary to confirm the issue.
issue is reproducible everywhere it seems!

@massaynus massaynus added the bug Issue was opened via the bug report template. label Dec 31, 2024
@github-actions github-actions bot added Developer Experience Issues related to Next.js logs, Error overlay, etc. Internationalization (i18n) Related to Internationalization with Next.js. Middleware Related to Next.js Middleware. Runtime Related to Node.js or Edge Runtime with Next.js. labels Dec 31, 2024
@a3har
Copy link

a3har commented Jan 1, 2025

Can you expand on what you mean here by

notice how the rewrite which has the app basePath and locale in it fails to execute the rewrite even if the url is computed correctly

I have a sandbox with your repo imported and it throws no errors either on the console or for the API calls for both failure and success urls.

Link: https://codesandbox.io/p/github/a3har/next-rewrite-issue/main

@massaynus
Copy link
Author

That's weird, because when I try it locally it still doesn't work 🤔

image

@massaynus
Copy link
Author

I thought maybe the one difference is that codesandbox uses pnpm so I tried using it still same behaviour (although it shouldn't make any difference)

image

@massaynus
Copy link
Author

massaynus commented Jan 1, 2025

Also one weird behavior, once a request passes to the rewritten URL, the one that is supposedly broken also starts to pass

2025-01-01.18-42-24.mp4

@massaynus
Copy link
Author

@a3har , to further expand in this:

notice how the rewrite which has the app basePath and locale in it fails to execute the rewrite even if the url is computed correctly

I mean if the requested URL has the basePath in it, even if the target URL which I want to forward the request to is computed correctly, calling NextResponse.rewrite with it fails to execute, and the response has a status of 400.

But if the requested URL omits the baseUrl, the rewrite is executed successfully 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. Developer Experience Issues related to Next.js logs, Error overlay, etc. Internationalization (i18n) Related to Internationalization with Next.js. Middleware Related to Next.js Middleware. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

No branches or pull requests

2 participants