sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
MIT License
13.86k stars 367 forks source link

In Next.js app: Only absolute URLs are supported #568

Closed baptisteArno closed 7 months ago

baptisteArno commented 7 months ago

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?

baptisteArno commented 7 months ago

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.