nuxt / http

Universal HTTP Module for Nuxt.js
https://http.nuxtjs.org
MIT License
229 stars 51 forks source link

globals.Headers is not a constructor #174

Open nlaitan opened 3 years ago

nlaitan commented 3 years ago

I get this error on a production environment, not in development mode. When I acess to link with a nuxt link in page, error doesn't ocurrs, only ocurrs when I enter on the page with url directly (refreshing for example also ocurrs)

Error stack:

ERROR  globals.Headers is not a constructor
  at mergeHeaders (node_modules_dev/ky/index.js:52:0)
  at deepMerge (node_modules_dev/ky/index.js:88:0)
  at validateAndMerge (node_modules_dev/ky/index.js:509:0)
  at Function.ky.<computed> [as get] (node_modules_dev/ky/index.js:516:0)
  at http_HTTP.module.exports.http_HTTP.<computed> [as get] (.nuxt/http.js:95:0)
  at http_HTTP.module.exports.http_HTTP.<computed> [as $get] (.nuxt/http.js:126:0)
  at asyncData (pages/catalogue.vue:36:0)
  at promisify (.nuxt/utils.js:278:0)
  at server.js:72810:23
  at Array.map (<anonymous>)
2021-04-13T02:52:13.304Z    ERROR   Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: globals.Headers is not a constructor","reason":{"errorType":"TypeError","errorMessage":"globals.Headers is not a constructor","stack":["TypeError: globals.Headers is not a constructor","    at mergeHeaders (node_modules_dev/ky/index.js:52:0)","    at deepMerge (node_modules_dev/ky/index.js:88:0)","    at validateAndMerge (node_modules_dev/ky/index.js:509:0)","    at Function.ky.<computed> [as get] (node_modules_dev/ky/index.js:516:0)","    at http_HTTP.module.exports.http_HTTP.<computed> [as get] (.nuxt/http.js:95:0)","    at http_HTTP.module.exports.http_HTTP.<computed> [as $get] (.nuxt/http.js:126:0)","    at asyncData (pages/catalogue.vue:36:0)","    at promisify (.nuxt/utils.js:278:0)","    at server.js:72810:23","    at Array.map (<anonymous>)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: globals.Headers is not a constructor","    at process.<anonymous> (/var/runtime/index.js:35:15)","    at process.emit (events.js:327:22)","    at processEmit [as emit] (/var/task/node_modules/signal-exit/index.js:161:32)","    at processPromiseRejections (internal/process/promises.js:245:33)","    at processTicksAndRejections (internal/process/task_queues.js:94:32)"]}
Unknown application error occurred

error is on a page, in this part:

  async asyncData({ $http }) {
    const data = await $http.$get(`xxx`)
    return { data }
  }

nuxt.config.js

...
modules: [
  '@nuxt/http'
]
...
http: {
    baseUrl: process.env.API_URL,
},

Versions:

@nuxt/http: 0.6.4
nuxt: 2.14.12
oritwoen commented 3 years ago

I also have this bug on production Vercel.

 ERROR  TypeError: globals.Headers is not a constructor  at server.js:52993:11  at http_HTTP.module.exports.http_HTTP.<computed> [as get] (.nuxt/http.js:113:0)  at http_HTTP.module.exports.http_HTTP.<computed> [as $get] (.nuxt/http.js:126:0)
thezzisu commented 3 years ago

+1 for Vercel.

globals.Headers is not a constructor
varna commented 3 years ago

Still doesn't work. Might have something to do with https://github.com/sindresorhus/ky-universal/issues/23 I tried to confirm that the latest release has https://github.com/nuxt/http/pull/121/files fix. But I can't wrap my head around which branch is 0.6.4

varna commented 3 years ago

I started receiving this after upgrading nuxt from 2.14.12 to 2.15.6