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

realFetch.call is not a function #15

Closed
jamespedid opened this issue May 8, 2018 · 7 comments
Closed

realFetch.call is not a function #15

jamespedid opened this issue May 8, 2018 · 7 comments

Comments

@jamespedid
Copy link

TypeError: realFetch.call is not a function
       at fetch (/usr/lib/leaguegamer/webserver/build/webpack:/datalibrary/node_modules/cross-fetch/dist/node-ponyfill.js:9:1)

When I inspect the import using the developer tools, the realFetch is an object, and not a function. On this object, there is the fetch function.

I'm unsure if this is a problem with the library or some kind of weird artifact that I have with the build. It would seem to be the latter, but I can't track it down. Any idea why require('node-fetch') is returning an object?

@lquixada
Copy link
Owner

that's strange. maybe node-fetch is not properly installed on your node_module. go to the /datalibrary/ and run node -p "require('node-fetch')". What's the output?

@jamespedid
Copy link
Author

I actually figured it out last night. It had to do with the way webpack was building the file. (I use webpack on the server-side too.) It was having trouble loading node-fetch in the right way. I was able to add node-fetch to the list of excludes and it solved the problem.

If anyone else has a problem like this, then this will remain here for troubleshooting.

@alexvetter
Copy link

Hi @lquixada,
Hi @jamespedid,

I'm currently facing the same issue. I upgraded from cross-fetch@1.1.1 to cross-fetch@2.2.0. After the upgrade I got the runtime error TypeError: realFetch.call is not a function.

I'm using cross-fetch in a webpack-bundled TypeScript backend.

If I change the require to require('node-fetch').default in ./node_modules/cross-fetch/dist/node-ponyfill.js it works like a charm.
If I import node-fetch instead of cross-fetch it also works.

Looks like others have kinda the same problem with node-fetch (node-fetch/node-fetch#450).

But I'm not sure how to fix this in our code. Perhaps it has something to do with your rollup build?

@lquixada
Copy link
Owner

lquixada commented Jun 1, 2018

Hi @alexvetter! I've identified the issue. The newer node-fetch version has two entry-points: main and module. When you require node files (without a bundler), it uses main. When you require bundled file (with target: node), it uses module.

The module entry point uses es modules, thus the "default" property works. I'm already working on a solution.

@alexvetter
Copy link

alexvetter commented Jun 1, 2018

Thank you very much! I would hoped I could have been of more value for fixing that issue. Really appreciate your fast response!

@lquixada
Copy link
Owner

lquixada commented Jun 2, 2018

no problem! btw, can you do npm install lquixada/cross-fetch in your project and make sure the patch worked?

@alexvetter
Copy link

I should have been more clear. Yes, it works! Thanks again. Looking forward to a official release.

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

3 participants