fetch-mock
fetch-mock copied to clipboard
Problem with abort controller + node-fetch v3(?)
I'm using v9.10.1 and getting TypeError: fetch-mock: Unrecognised Request object. Read the Config and Installation sections of the docs
.
I've isolated it to a combination of using AbortController + node-fetch v3 (via ky-universal). Yes, node-fetch v3 is currently in beta, so perhaps this isn't the most critical of issues.
Take a look at https://repl.it/@markwoon/fetch-mock-568.
Switch between ky-universal 0.6.0
and 0.7.0
. 0.6.0
works but 0.7.0
does not. The change from 0.6.0 and 0.7.0 is the use of node-fetch v3.
Removing AbortController also eliminates the problem (https://repl.it/@markwoon/fetch-mock-568-no-abortcontroller).
Cheers for the tip off - I'll start running tests against node-fetch 3 and hopefully resolve it
Have you raised this on ky-universal? IMHO it's a really bad idea for them to bundle a beta of node-fetch.
But I see what the problem is.
fetch-mock declares a peerDependency on node-fetch: "*"
and npm ignores prerelease tags when installing the peer dependency, so it installs [email protected]. This means fetch-mock is using 2.6.0 but ky is using the beta, so fetch-mock is using different constructors to the actual ky library, and is unable to correctly identify Request, Response, Headers etc
I've raised an issue wth npm to clarify the peerDependency behaviour is correct: https://github.com/npm/node-semver/issues/329
I've also tried modifying your repl to directly install "node-fetch": "^3.0.0-beta.6-exportfix"
at the root, which in theory should fix it, but it's having no effect. Will try to replicate locally
I'm seeing that repl.it is installing peerDependencies, which forces the use of [email protected]. When I install and run the same code locally it does not install the peerDependencies. It looks like it uses [email protected]
, which shouldn't exhibit this behaviour, so is probably doing something additional to force peer dependency installation as a convenience for users, but in this case the behaviour is unexpectedly harmful.
Are you experiencing the bug locally? Are you able to share a repo I can install to see for myself whats going on.
Yeah, I'm seeing this problem locally. Unfortunately it's in a private repo. I was hoping the repl.it would be enough to reproduce.
As for ky-universal, I'm just sticking with 0.6 for now. I'm hoping things will resolve itself by the time node-fetch 3 is released.