question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clone fails on Node: global.fetch is not a function

See original GitHub issue

From 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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
wmhiltoncommented, Feb 4, 2020

Yes… it’s really a webpack configuration issue. Webpack is probably trying to use the module file instead of the main file, but

  • the module file uses ES6 modules and is “for web” while
  • the main 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 to dist/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.

1reaction
strogonoffcommented, Mar 7, 2020

@wmhilton I believe https://www.electron.build? That’s what we’re using!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found