Skip to content

Conversation

@lvzhenbo
Copy link
Contributor

@lvzhenbo lvzhenbo commented Dec 8, 2025

  1. While troubleshooting the download timeout issue, I discovered the following problems:
  2. The node-fetch dependency has not been updated for a long time, and its upstream dependency node-domexception has been abandoned.
  3. The download proxy settings were not actually taking effect.
  4. So I replaced node-fetch with axios, which supports proxies.

@1111mp
Copy link
Owner

1111mp commented Dec 8, 2025

Starting with version 21, Node.js has consistently supported the native fetch API, so I feel that switching to the native fetch would be better.

@lvzhenbo
Copy link
Contributor Author

lvzhenbo commented Dec 8, 2025

But native fetch doesn't seem to support proxies
To be precise, proxy support is not yet available.

@1111mp
Copy link
Owner

1111mp commented Dec 8, 2025

image

This can be achieved through here.

import { ProxyAgent, setGlobalDispatcher } from "undici";

// ...

const httpProxy =
    process.env.HTTP_PROXY ||
    process.env.http_proxy ||
    process.env.HTTPS_PROXY ||
    process.env.https_proxy;

if (httpProxy) {
  const dispatcher = new ProxyAgent(httpProxy);
  setGlobalDispatcher(dispatcher);
}

// ...

@1111mp
Copy link
Owner

1111mp commented Dec 8, 2025

Starting from Node.js v24, fetch() can automatically use proxy settings without additional code or ProxyAgent. Enable this feature by setting:

export NODE_USE_ENV_PROXY=1
export HTTP_PROXY="http://proxy.example.com:8080"
export HTTPS_PROXY="http://proxy.example.com:8080"
export NO_PROXY="localhost,127.0.0.1,.internal.example.com"

With NODE_USE_ENV_PROXY=1, fetch() respects HTTP_PROXY, HTTPS_PROXY, and NO_PROXY environment variables.
For details, see the implementation PR: nodejs/node#57165

@lvzhenbo
Copy link
Contributor Author

lvzhenbo commented Dec 8, 2025

If you want to use native fetch, then I will close this PR

@1111mp
Copy link
Owner

1111mp commented Dec 8, 2025

I think we can keep the PR open.

image This can be achieved through here.
import { ProxyAgent, setGlobalDispatcher } from "undici";

// ...

const httpProxy =
    process.env.HTTP_PROXY ||
    process.env.http_proxy ||
    process.env.HTTPS_PROXY ||
    process.env.https_proxy;

if (httpProxy) {
  const dispatcher = new ProxyAgent(httpProxy);
  setGlobalDispatcher(dispatcher);
}

// ...

Currently, I prefer this option.

However, it seems reasonable to upgrade the Node.js version used by the project since its inception to v24 (currently v20).

@1111mp
Copy link
Owner

1111mp commented Dec 8, 2025

If you want to use native fetch, then I will close this PR

I still believe this PR is fully relevant, so there is no need to close it. The next step is to finalize the solution and proceed with implementation.

@lvzhenbo
Copy link
Contributor Author

lvzhenbo commented Dec 8, 2025

Alright, I'm leaning toward a mature, ready-to-use solution since I did run into issues downloading the binary files. Feel free to reach out if you need further assistance.

Signed-off-by: The1111mp <[email protected]>
@1111mp
Copy link
Owner

1111mp commented Dec 13, 2025

@lvzhenbo If you have time, could you check whether the latest code works as expected. Is the agent working as expected?

@lvzhenbo
Copy link
Contributor Author

The proxy for undici can be used.
image

@1111mp 1111mp merged commit 6d0c196 into 1111mp:tauri Dec 15, 2025
@lvzhenbo lvzhenbo deleted the node-fetch-to-axios branch December 15, 2025 12:41
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

Successfully merging this pull request may close these issues.

2 participants