Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.3K
Views
El middleware Next.js v12 no funciona con node-fetch y axios

Actualmente estoy tratando de crear un middleware que obtenga los datos del usuario al obtener un punto final externo con Axios. Axios tampoco funciona con el middleware. Aquí está mi error al usar node-fetch:

 Module build failed: UnhandledSchemeError: Reading from "node:buffer" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs.

¿Alguna idea de por qué sucede esto?

Aquí está mi código:

 import fetch from "node-fetch" import { getSession } from "next-auth/react"; import { NextMiddleware, NextResponse } from "next/server"; export const middleware: NextMiddleware = async (req, ev) => { const session = await getSession() as any; const user = await fetch("some-url", { headers: { Authorization: `Bearer ${session?.user?.someproperty}`, }, }); if (user.statusCode !== 200) return NextResponse.redirect(req.url); else return NextResponse.next(); };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En mi caso, estaba usando axios dentro del middleware y obtuve el siguiente error

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

Tuve que instalar axios-fetch-adapter de acuerdo con esta pregunta

Mi código quisiera

 import type { NextFetchEvent, NextRequest } from 'next/server' import fetchAdapter from '@vespaiach/axios-fetch-adapter' import axios from 'axios' export async function middleware(req: NextRequest, ev: NextFetchEvent) { const axiosInstance = axios.create({ adapter: fetchAdapter }) const data = await axiosInstance.get('/whatever-url') // the rest of the code }

O si ya tenía una instancia preconfigurada con opciones personalizadas

 import type { NextFetchEvent, NextRequest } from 'next/server' import fetchAdapter from '@vespaiach/axios-fetch-adapter' import axiosInstance from './the-path-of-your-instance' export async function middleware(req: NextRequest, ev: NextFetchEvent) { axiosInstance.defaults.adapter = fetchAdapter const data = await axiosInstance.get('/whatever-url') // the rest of the code }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!