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

axios & middleware error - adapter is not a function #30932

Closed
SKumarSpace opened this issue Nov 4, 2021 · 4 comments
Closed

axios & middleware error - adapter is not a function #30932

SKumarSpace opened this issue Nov 4, 2021 · 4 comments
Assignees
Labels
bug Issue was opened via the bug report template. Middleware Related to Next.js Middleware

Comments

@SKumarSpace
Copy link

SKumarSpace commented Nov 4, 2021

What version of Next.js are you using?

12.0.2

What version of Node.js are you using?

14.16.0

What browser are you using?

Microsoft Edge (Chromium)

What operating system are you using?

Windows

How are you deploying your application?

next dev

Describe the Bug

Unable to call axios from middleware.
When I do, I receive the following error:

error - node_modules\axios\lib\core\dispatchRequest.js (58:0) @ dispatchRequest
TypeError: adapter is not a function

image

I also tried this with next@canary, but it also has the same issue.

Expected Behavior

Http Request from Axios should go through

To Reproduce

  • Create _middleware.ts file
  • Call Axios Get request inside middleware
const resp = await axios.get('https://httpbin.org/ip');
@SKumarSpace SKumarSpace added the bug Issue was opened via the bug report template. label Nov 4, 2021
@timneutkens timneutkens added the Middleware Related to Next.js Middleware label Nov 4, 2021
@davidecutrupi
Copy link

I have the same problem.
Using the fetch function it works.

@Kikobeats
Copy link
Member

Probably the thing that is happening there is axios is using some Node.js modules and the Edge Function is running in a Web Runtime where Node.js APIs are missing.

Why not just use fetch? It's global, it's standard, it's expected.

@Kikobeats
Copy link
Member

After investigation, we determine what is happening is axios delegates into XMLHttpRequest and it's missing on the Edge Function; this is a limitation right now can't be resolved in the short term; also Axios is working in a new version that uses fetch instead, so there is not too much we can do right now.

I recommend you to use native fetch or ky in case you want some sugar syntactic over fetch API.

shantanuraj added a commit to shantanuraj/podcst-web that referenced this issue Dec 25, 2021
- Fixed blocker with sources in src/ directory and using experimental
features
- Drop axios vercel/next.js#30932
- Using fetch's json method causes isPlainObject check to fail
  https://github.com/vercel/next.js/blob/c88898be120bf598958438b9bc07cc6fe6c4636a/packages/next/lib/is-serializable-props.ts#L13
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
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. Middleware Related to Next.js Middleware
Projects
None yet
Development

No branches or pull requests

5 participants