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

Fail to match a request path to its app route if using basePath on edge runtime #49661

Closed
1 task done
antoineol opened this issue May 11, 2023 · 5 comments · Fixed by #52910
Closed
1 task done

Fail to match a request path to its app route if using basePath on edge runtime #49661

antoineol opened this issue May 11, 2023 · 5 comments · Fixed by #52910
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@antoineol
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #22 SMP Tue Jan 10 18:39:00 UTC 2023
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.19
      pnpm: 8.4.0
    Relevant packages:
      next: 13.4.2-canary.5
      eslint-config-next: 13.4.1
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.0.4

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/repro-basepath-for-routes-rzyh8z?file=%2Fapp%2FSendRequest.tsx%3A13%2C84

To Reproduce

Load the sandbox. The preview should show an error 500. The server logs show:

- error Invariant: no match found for request. Pathname '/mysubpath/api' should have matched '/api'

Describe the Bug

What happens behind the scene:

  • A basic route is created with the "edge" runtime
  • A basePath is set in next.config.js ("/mysubpath")
  • A basic fetch is done in the front to "/mysubpath/api", which errors.

But if the route runtime is set back to the default (comment runtime = "edge"), it works as expected.

The file node_modules/next/dist/esm/server/web/edge-route-module-wrapper.js seems to be related to the issue. The basePath does not seem to be used there, so the URL path and the route matcher don't match.

Expected Behavior

Fetching the routes works with a basePath and the edge runtime without error.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@antoineol antoineol added the bug Issue was opened via the bug report template. label May 11, 2023
@github-actions github-actions bot added area: app App directory (appDir: true) Runtime Related to Node.js or Edge Runtime with Next.js. Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels May 11, 2023
@antoineol antoineol changed the title basePath seems not used to match the path of "app" routes (api) on edge runtime Fail to match a request path to its app route if using basePath on edge runtime May 12, 2023
@shreecodes
Copy link

We are hitting this too. This effectively makes basePath unusable with the edge runtime, which is a major deficiency.

@shaneafsar
Copy link

Same -- we're running into this currently while trying to generate open graph images (we use app directory and basePath)

@kodiakhq kodiakhq bot closed this as completed in #52910 Jul 19, 2023
kodiakhq bot pushed a commit that referenced this issue Jul 19, 2023
Fixes a bug where the edge runtime didn't support `basePath` with Custom App Routes.

- Fixes #49661
@rafalzawadzki
Copy link

I have exact same error but without using basePath but with a rewrite:

async rewrites() {
    return [
      {
        source: "/path/:id",
        destination: "/api/path/:id" // Proxy to API with edge runtime
      }
    ];
  }

couldn't find any documentation for why this doesn't work! leaving this comment just in case someone stumbles on this problem too. What worked for me was disabling edge runtime in the api route handler.

@maccman
Copy link

maccman commented Aug 13, 2023

I have exact same error but without using basePath but with a rewrite:

async rewrites() {
    return [
      {
        source: "/path/:id",
        destination: "/api/path/:id" // Proxy to API with edge runtime
      }
    ];
  }

couldn't find any documentation for why this doesn't work! leaving this comment just in case someone stumbles on this problem too. What worked for me was disabling edge runtime in the api route handler.

also running into this

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants