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.

fetch and electron renderer fail

See original GitHub issue

In a electron renderer thread if you don’t bundle (nodeIntegration===true) you get whatever main prop a package points to, in this case we get the node version of ky.

But if we look at these lines https://github.com/sindresorhus/ky-universal/blob/master/index.js#L14-L16 we will get into troubles because the if clause tests if global.fetch exists and in electron renderer that will be true because native web fetch is available.

So instead of using node-fetch we use native fetch, but when another package using ky uses https://github.com/form-data/form-data with fetch it fails because form-data only works with node-fetch.

To fix this either we detect the environment for this specific case and workaround it or we remove the if clauses since ky already allows for lazy resolution of globals.

I’m happy to PR a fix, but would like some feedback on this first.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Richienbcommented, Feb 6, 2020

This problem should be fixed by https://github.com/node-fetch/node-fetch/pull/603 in node-fetch v3 since it duck tests for FormData.

0reactions
Richienbcommented, Mar 17, 2020

In the browser context, you can just import ky with const ky = require("ky/umd").

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to use Node.js APIs in renderer process - Stack Overflow
Update: the answer below is a workaround. You should not disable contextIsolation and you should not enable nodeIntegration .
Read more >
electron-fetch - npm
A light-weight module that brings window.fetch to electron's background process. Latest version: 1.9.1, last published: 3 months ago.
Read more >
webContents | Electron
Emitted when the renderer process unexpectedly disappears. This is normally because it was crashed or killed. Event: 'unresponsive'​. Emitted when the web page ......
Read more >
electron-fetch | Yarn - Package Manager
electron -fetch ; Stay consistent with window.fetch API. Runs on both Electron and Node.js, using either Electron's net module, or Node.js http module...
Read more >
Electron | Sentry Documentation
You need to call init in the main process and every renderer process you spawn. ... import * as Sentry from "@sentry/electron"; Sentry.init({...
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