I use ky-universal, which is built on top of node-fetch. After upgrading to Next.js 9.4, it has started throwing "Only absolute URLs are supported" errors on the Node.js side, even though an absolute URL is set and it works on Next.js 9.3.x.
ky-universal in a Next.js project to make a request on the server side."Only absolute URLs are supported" error.Shouldn't throw an error, and should work like it did in Next.js 9.3.x.
It looks like the default polyfill is interfering with the library somehow, but I can't figure out what/how. Also, pasting from https://github.com/zeit/next.js/pull/12353#issuecomment-627064091 —
node-fetchhas an upcoming v3 release (in beta now) that fixes a long-standing issue, andky-universalis in the process of using it in their next release, which is vital when working with large API payloads.
Similar reports —
I thought that with Next.js 9.4 it would be possible to use ky instead of ky-universal, as fetch is already polyfilled by Next.js.
Is this not the case?
The suggestion to use ky instead of ky-universal is something I did not try and I thought would work. However, trying just the ky package ends up with a message SyntaxError: Unexpected token 'export'
Yep, can confirm.
Same issue with "Unexpected token 'export'" :/
Will stick to vanilla fetch for the time being.
I have encountered the same error.
For the time being, I added the following code and the error is gone.
if (typeof window === 'undefined')
(global as any).fetch = require('node-fetch');
@YukiKitagata Thanks for the temporary workaround. Where exactly is this used? _app?
@paambaati I'm using ky.extend, so I'm adding it before call ky.extend.
@YukiKitagata Can you show us an example? I can't seem to find this extensions API in Ky's documentation.
@paambaati
Sorry, that was a typo on my part.
ky.extensions is a mistake for ky.extend.
I tried adding it to the top of _app and it worked well.
I was able to put the fix by @YukiKitagata into practice. Wanted to paste it here for @paambaati and anyone else that may be unclear of how to implement it.
1) Run npm i node-fetch
2) Modify the _app.tsx like below.
3) Using ky.post or anything else ky related works again as expected.
import ky from 'ky-universal';
if (typeof window === 'undefined')
(global as any).fetch = require('node-fetch');
function MyApp({ Component, pageProps }: AppProps): JSX.Element {
Hey! Thanks for the report, I've fixed the issue here: #12804
@timneutkens

@timneutkens Thanks, I can confirm that this is fixed and ky-universal works fine on 9.4.1-canary.1.
Most helpful comment
@timneutkens Thanks, I can confirm that this is fixed and
ky-universalworks fine on9.4.1-canary.1.