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

Problem with abort controller + node-fetch v3(?) #568

Open
markwoon opened this issue May 31, 2020 · 4 comments
Open

Problem with abort controller + node-fetch v3(?) #568

markwoon opened this issue May 31, 2020 · 4 comments

Comments

@markwoon
Copy link

markwoon commented May 31, 2020

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).

@wheresrhys
Copy link
Owner

Cheers for the tip off - I'll start running tests against node-fetch 3 and hopefully resolve it

@wheresrhys
Copy link
Owner

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 node-fetch@2.6.0. 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: npm/node-semver#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

@wheresrhys
Copy link
Owner

I'm seeing that repl.it is installing peerDependencies, which forces the use of node-fetch@2.6.0. When I install and run the same code locally it does not install the peerDependencies. It looks like it uses npm@6.16.4, 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.

@markwoon
Copy link
Author

markwoon commented Jun 1, 2020

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.

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