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

"Failed to convert value to 'ReadableStream'" and "fetch failed" #1845

Closed
FedeIlLeone opened this issue Dec 29, 2022 · 3 comments
Closed

"Failed to convert value to 'ReadableStream'" and "fetch failed" #1845

FedeIlLeone opened this issue Dec 29, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@FedeIlLeone
Copy link

Bug Description

I'm unable to use undici.fetch in an electron app + webpack config. I did some tests and I get these errors after #1793 . I thought it was a problem with my app, but I tried in a new project without other dependencies (just electron + webpack) and I keep getting these errors.

With a GET request, this is the error:

bundle.js:5767 Uncaught (in promise) TypeError: Failed to execute 'pipeThrough' on 'ReadableStream': Failed to read the 'readable' property from 'ReadableWritablePair': Failed to convert value to 'ReadableStream'.
    at dA (bundle.js:5767:40)
    at cA (bundle.js:5694:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
dA @ bundle.js:5767
cA @ bundle.js:5694
processTicksAndRejections @ node:internal/process/task_queues:96

With a POST request:

bundle.js:1451 Uncaught (in promise) TypeError: fetch failed
    at A.exports.fetch (bundle.js:1451:21)
    at async bundle.js:9562:14

GET requests proceed but POST do not.

Could it be a webpack problem or something else with my setup? If I use undici.fetch without any dependencies then everything is good.

Reproducible By

As mentioned before, I was able to reproduce it in a new project with a basic webpack configuration to divide the main and renderer process. Everything I tried was done in the renderer process. This is the script used:

const { fetch } = require("undici");

(async () => {
	const getRes = await fetch("https://jsonplaceholder.typicode.com/posts").then((res) => res.json());
	console.log("GET ->", getRes);

	const postRes = await fetch("https://jsonplaceholder.typicode.com/posts", {
		method: "POST",
		body: `{"title":"foo","body":"bar","userId":1}`,
		headers: {
			"content-type": "application/json;charset=utf-8"
		}
	}).then((res) => res.json());
	console.log("POST ->", postRes);
})();

With v5.13.0 you receive the response in output, but not with v5.14.0.

Expected Behavior

Use undici.fetch in electron + webpack, as before in v5.13.0.

Logs & Screenshots

image

Environment

Windows 11 Pro 22621.963, Node v19.3.0

@FedeIlLeone FedeIlLeone added the bug Something isn't working label Dec 29, 2022
@mcollina
Copy link
Member

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

@ronag
Copy link
Member

ronag commented Dec 30, 2022

Sounds more like a electron/webpack issue with web streams. Doesn't seem related to undici.

@FedeIlLeone
Copy link
Author

I've done some more tests, webpack has nothing to do with it, it seems to be electron. I've used undici.fetch in the main process of electron and no errors, but is causing issues in the renderer process.

Unsure if I still have to give the steps to reproduce, since I think the problem is electron. I think I'll have to use undici.fetch in the main process.

@ronag ronag closed this as completed Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants