remix
remix copied to clipboard
fetch() doesn't return correct Response type
What version of Remix are you using?
1.7.2
Steps to Reproduce
Inside the remix project try
const a = await fetch('https://google.com')
console.log('a instanceof Response: ', a instanceof Response) // -> false
This probably has to do with this commit: https://github.com/remix-run/remix/commit/25b4c83b10c5bc4d84ea81407e7de1a0e4f43df4#diff-87ec1c3c130fe3481b9f1c542b1d8a53548882d33c73c68b894fd442d606afc0
A current workaround I found thanks to @milamer is to include
import { Response } from '@remix-run/web-fetch'
in the file.
Expected Behavior
instanceof Response should be true
Actual Behavior
instanceof Response is false
Hi @christian-reichart, where are you importing fetch from?
Hi @machour , I don't import it specifically, so it's the global fetch.
Any reason why you're not using remix's fetch?
import { fetch } from "@remix-run/node";
Thanks for your response @machour ! Correct me if I'm wrong but I was under the impression that Remix is supposed to let you use fetch and Response without any import. https://remix.run/docs/en/v1/other-api/fetch Is the documentation outdated?
Now I'm the one confused 😅 I'll circle back with the team on this point and let you know what's the right approach, and will update the docs if necessary.
In the meantime, does using fetch from @remix-run/node fix your original issue?
You might also be interested in reading the "Moving closer to The Platform™" part from the 1.5.0 release notes : https://github.com/remix-run/remix/releases/tag/v1.5.0
@machour I have run into this issue with reimix-run/node and external libraries that use globals and instanceof Response.
I have been able to work around but latest is in a nested dependency using oauth4webapi
Any thoughts from the team yet on how to fix the inconsistent globals?
In the router they worked around it as well for more context
https://github.com/remix-run/react-router/pull/9690
Although if it is an issue with esm vs cjs not sure what the solution could be
Found fix and made a merge request.
Here is patch that can be used with patch-package https://gist.github.com/acoreyj/37eff1fdc459dbea31515d5d40be7b35
Should be closed by https://github.com/remix-run/remix/pull/7109
🤖 Hello there,
We just published version v0.0.0-nightly-a179aa7-20230809 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!
Thanks!
🤖 Hello there,
We just published version v0.0.0-nightly-b1149bb-20230810 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!
Thanks!