import ky from 'ky'
import { NextApiRequest, NextApiResponse } from 'next'
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
await ky.get("https://google.com")
res.status(200).json({ name: 'John Doe' })
}
In the above api route (using pages routeer) code I expected fetch to resolve to built-in global fetch method
but I get the error below
builder:dev: тип TypeError: Only absolute URLs are supported
builder:dev: at getNodeRequestOptions (webpack-internal:///../../node_modules/.pnpm/[email protected]/node_modules/node-fetch/lib/index.js:1327:9)
builder:dev: at eval (webpack-internal:///../../node_modules/.pnpm/[email protected]/node_modules/node-fetch/lib/index.js:1450:19)
builder:dev: at new Promise (<anonymous>)
builder:dev: at Object.fetch (webpack-internal:///../../node_modules/.pnpm/[email protected]/node_modules/node-fetch/lib/index.js:1447:9)
That suggests that the indirect dependency [email protected] was being used instead of the global, built-in fetch method in nodejs 18+
I tried manually overriding the fetch for ky using
await ky.get("https://google.com" { fetch: global.fetch })
It still doesn't do as I wanted.