Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofetch.native fails with: 'fetch' called on an object that does not implement interface Window. #272

Closed
cosbgn opened this issue Aug 23, 2023 · 2 comments

Comments

@cosbgn
Copy link

cosbgn commented Aug 23, 2023

Environment

Nuxt 3.6.5

Reproduction

https://stackblitz.com/edit/github-9ukebr-xnzf5u?file=pages%2Findex.vue

Describe the bug

ofetch.native fails with: 'fetch' called on an object that does not implement interface Window.

Additional context

You can reproduce it with:

<template>
	<div>
	  <div>{{ res.fetch }}</div>

	  <hr />

	  <div>
		{{ res.ofetch }}
		// ofetch fails with: `Uncaught (in promise) TypeError: 'fetch' called on an object that does not implement interface Window.`
	</div>
	</div>
  </template>
  
  <script setup>
  const res = ref({ fetch: null, ofetch: null })
  onMounted(async () => {
	const url = 'https://jsonplaceholder.typicode.com/todos/1'
	res.value.fetch = await fetch(url).then((r) => r.json())
	res.value.ofetch = await $fetch.native(url).then((r) => r.json())
  })
  </script>
  

Logs

No response

@pi0 pi0 closed this as completed in 107c99a Aug 23, 2023
@pi0
Copy link
Member

pi0 commented Aug 23, 2023

Hi dear @cosbgn. Thanks for making the reproduction. I have pushed a fix which will be available in next release 👍🏼

It seems you are using an old version of nuxt 3 (3.0.0 betas) with older ohmyfetch dependency. Please consider using latest nuxt version (or edge channel https://nuxt.com/docs/guide/going-further/edge-channel)

@cosbgn
Copy link
Author

cosbgn commented Aug 23, 2023

Thanks a lot. I'm actually using the latest, I just found this stackblitz online and the error appeared also there, so it was easier to just fork that rather than building a new one.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants