Skip to content

context.options.headers.get is not a function in Nuxt 4.2.0 with ofetch 1.5.0 #522

@Flo0806

Description

@Flo0806

Environment

Since the latest version 1.5.0 ofetch throws an error if $fetch it used in Nuxt 4.2.0.

Linked issue: nuxt/nuxt#33604 (comment)

Reproduction:

I've made small reproduction of this issue
https://stackblitz.com/edit/github-kbqwxvpo?file=app%2Fapp.vue
In App.vue file, I create new $fetch client and tries to send POST request with body and in console, you will see the error

Reproduction

<script setup lang="ts">
const httpOptions = {
  baseURL: '/api',
  credentials: 'include',
  headers: {
    Accept: 'application/json',
  },
  retry: false,

  async onRequest({ options, request }) {
    options.headers = {
      Accept: 'application/json',
    };
    console.log(options.headers);
  },
};

const client = $fetch.create(httpOptions);

const test = async () => {
  console.log('SEND POST REQUEST');
  client('/login', {
    method: 'post',
    body: {
      email: 'test@mail.com',
      password: '12312313',
    },
  });
};
</script>

<template>
  <div>
    <button @click="test">click</button>
  </div>
</template>

<style scoped></style>

This code will log a browser error: context.options.headers.get is not a function

Describe the bug

It throws the error context.options.headers.get is not a function if custom headers are set when using $fetch in a Nuxt 4.2.0 project.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions