ky-universal: TypeError: Headers is not a constructor

I’ve had a somewhat frustrating start to ky, not sure what I’m doing wrong

(node:29176) UnhandledPromiseRejectionWarning: TypeError: Headers is not a constructor
    at new Ky (/Volumes/Repositories/Private/apitests/testProj1/node_modules/ky/umd.js:211:20)
    at Function.ky.(anonymous function) [as get] (/Volumes/Repositories/Private/apitests/testProj1/node_modules/ky/umd.js:389:37)
    at getParentChildEndpoint (/Volumes/Repositories/Private/apitests/testProj1/src/api/util/getParentChildEndpoint.js:14:16)
    at Object.getStatus (/Volumes/Repositories/Private/apitests/testProj1/src/api/instanceApi.js:49:22)

Rerproduced like this:

const ky = require('ky-universal').default;

const prefix = 'http://aa9da6ff.ngrok.io/api/instances/gub6r';
const instanceApi = ky.create({ prefixUrl: prefix, throwHttpErrors: false });
const result = await instanceApi.get('status').json();

This seems to be line 211 in umd.js: Screenshot 2019-06-17 at 11 15 57

I have both KY and Ky-universal installed. What am I doing wrong or missing?

If I try to catch this, the error is the same as that shown in the stack trace. I’d expect a HTTP error (like 404), not a stack trace like this. Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 21 (1 by maintainers)

Most upvoted comments

If it helps, I’ve a simple test case for this @ https://github.com/markwoon/ky-universal-jest

Just run:

# yarn build
# node dist/main.bundle.js

@szmarczak Or we can just check each global individually?