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

TypeError: s is not a function occurs when api routes do not match. #59846

Closed
1 task done
skyddyyu opened this issue Dec 21, 2023 · 4 comments
Closed
1 task done

TypeError: s is not a function occurs when api routes do not match. #59846

skyddyyu opened this issue Dec 21, 2023 · 4 comments
Labels
bug Issue was opened via the bug report template. locked Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@skyddyyu
Copy link

Link to the code that reproduces this issue

https://github.com/skyddyyu/api-route-mismatch

To Reproduce

1.There is an api route /api/rest/upload in the project for file upload. When I accidentally enter the wrong routing address, such as api/ant/upload, an error message appears: TypeError: s is not a function.

Current vs. Expected behavior

There is an api route /api/rest/upload in the project for file upload. When I accidentally enter the wrong routing address, such as api/ant/upload, an error message appears: TypeError: s is not a function. This is not true. Expected to happen. At the same time, if the route cannot be recruited, there should be a friendly response. The request status and code should be 404. At the same time, different response information should be returned under different data type requests to provide a friendly reminder to the developer.
api-route-mismatch
no-prompt

Verify canary release

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

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 18.18.2
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.0.4
  eslint-config-next: 14.0.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

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

App Router, Middleware / Edge (API routes, runtime)

Additional context

No response

@skyddyyu skyddyyu added the bug Issue was opened via the bug report template. label Dec 21, 2023
@github-actions github-actions bot added the Runtime Related to Node.js or Edge Runtime with Next.js. label Dec 21, 2023
@jupapios
Copy link

jupapios commented Dec 26, 2023

I was able to reproduce this bug on my production app (in practice it can be reproduced against any production app),

Screenshot 2023-12-25 at 7 34 56 PM

To add more context, the problem happens when you send a multipart/form-data (it does NOT happen with x-www-form-urlencoded) to a non-existent route.

ie,

POST /404-route HTTP/1.1
Host: localhost:3000
Content-Length: 128
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="hi"

hi
------WebKitFormBoundary7MA4YWxkTrZu0gW--

returns a 500 instead of 404.

@codebackup91
Copy link

I have a couple of logs with the same error on a webhook I exposed.
To elaborate on the repro steps, if you see a 405 error you probably have a middleware on top (ie next-auth or next-intl's middlewares), so just make sure the route you're testing against doesn't have one.

Here's a one line repro curl https://demo.vercel.store/api --form foo="bar"

@huozhi
Copy link
Member

huozhi commented Jan 11, 2024

Fixed by #60526

@huozhi huozhi closed this as completed Jan 11, 2024
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 Jan 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants