Clone fails on Node: global.fetch is not a function
See original GitHub issueFrom a quick scan, it looks like as of this change in January 2019 http
module no longer checks for global.fetch
, which excludes Node environment.
I was accidentally stuck on 0.50 version, and once I updated (for the sake of fastCheckout
and other niceties) I’m getting the following stack trace when cloning:
16:00:17.707 › UnhandledRejection TypeError: global.fetch is not a function
at http (webpack-internal:///./node_modules/isomorphic-git/dist/for-future/isomorphic-git/index.js:4931:28)
at Function.discover (webpack-internal:///./node_modules/isomorphic-git/dist/for-future/isomorphic-git/index.js:5162:21)
at fetchPackfile (webpack-internal:///./node_modules/isomorphic-git/dist/for-future/isomorphic-git/index.js:5975:42)
at fetch (webpack-internal:///./node_modules/isomorphic-git/dist/for-future/isomorphic-git/index.js:5840:22)
at Module.clone (webpack-internal:///./node_modules/isomorphic-git/dist/for-future/isomorphic-git/index.js:6321:42)
From cursory search, it seems like global.fetch
isn’t supposed to be available on Node. Is reinstating the previous Node-compatible state of http
’s fetching logic on the table?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top Results From Across the Web
ReferenceError: fetch is not defined - javascript - Stack Overflow
It seems fetch support URL scheme with "http" or "https" for CORS request. Install node fetch library npm install node-fetch , read the...
Read more >Top 10 Most Common Node.js Developer Mistakes - Toptal
Trying to fetch an user object from the database. Node.js is free to run other parts of the code from the moment this...
Read more >Using the Fetch API - MDN Web Docs
The Fetch API provides a JavaScript interface for accessing and manipulating parts of the protocol, such as requests and responses.
Read more >simple-git - npm
To resolve these issues, either upgrade to a newer version of node.js or ensure you are using the necessary polyfills from core-js -...
Read more >Global objects | Node.js v19.3.0 Documentation
The following variables may appear to be global but are not. They exist only in the scope ... A browser-compatible implementation of the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes… it’s really a webpack configuration issue. Webpack is probably trying to use the
module
file instead of themain
file, butmodule
file uses ES6 modules and is “for web” whilemain
file uses CommonJS modules and is “for node”Which 99% of the time is right, because Webpack is usually not used on Node.js apps. You can probably make Webpack use the “right” version with an
alias
todist/for-node/isomorphic-git/index.js
but if you’re using webpack and isomorphic-git on both the node-side and the browser-side of an Electron app, you’d need separate webpack config files…Anyway, as you can see it’s obviously a bit of a mess. And I am going to fix this in version 1.0 by pulling this troublesome bit out of the library completely and make users provide an HTTP client, just like what I already do for
fs
. That way the code doesn’t have to try and detect whether it’s running in Node or be compiled differently.@wmhilton I believe https://www.electron.build? That’s what we’re using!