sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In Next.js app: Only absolute URLs are supported

baptisteArno opened this issue · comments

I'm super confused I get this error on a Next.js app (latest) server-side:

Something went wrong TypeError: Only absolute URLs are supported
builder:dev:     at getNodeRequestOptions (webpack-internal:///../../node_modules/.pnpm/node-fetch@2.7.0/node_modules/node-fetch/lib/index.js:1328:9)
builder:dev:     ... 8 lines matching cause stack trace ...
builder:dev:     at async Ky._retry (webpack-internal:///(api)/../../node_modules/.pnpm/ky@1.2.3/node_modules/ky/distribution/core/Ky.js:227:20)
const response = await ky
          .get('https://domain.com/v1/projects', {
            headers: {
              Authorization: `Bearer ${apiKey}`,
            },
          })
          .json()

It seems it calls node-fetch library. My Node.js version is v20.8.1

Maybe an issue when webpack transpiles the code?

Issue on my side.

@mistralai/mistralai package was mistakenly imported on the client side which was overwriting the fetch definition. Which subsequently broke ky behavior.