Could not resolve a bunch of packages

Hi, I am trying to make a simple thing to send requests thru an authenticated proxy, but for some reason when I try to build, I get a bunch of errors.
X [ERROR] Could not resolve "worker_threads"

node_modules/undici/lib/fetch/constants.js:3:57:
3 │ ... MessageChannel, receiveMessageOnPort } = require('worker_threads')
╵ ~~~~~~~~~~~~~~~~

The package "worker_threads" wasn't found on the file system but is built into node. Are you trying
to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
X [ERROR] Could not resolve "worker_threads"

node_modules/undici/lib/fetch/constants.js:3:57:
3 │ ... MessageChannel, receiveMessageOnPort } = require('worker_threads')
╵ ~~~~~~~~~~~~~~~~

The package "worker_threads" wasn't found on the file system but is built into node. Are you trying
to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
I get this error but for async_hooks stream/web util/types perf_hooks diagnostics_channel and of course, worker_threads
7 Replies
user
userOP17mo ago
This started to happen after I added this snippet
function getAgent(env: Env): ProxyAgent {
const agent = new ProxyAgent({
uri: env.proxyHost,
token: `Basic ${Buffer.from(env.proxyAuth).toString('base64')}`,
});

return agent;
}
function getAgent(env: Env): ProxyAgent {
const agent = new ProxyAgent({
uri: env.proxyHost,
token: `Basic ${Buffer.from(env.proxyAuth).toString('base64')}`,
});

return agent;
}
wrangler.toml has node_compat set to true I am still having this problem. It seems to only happen when i import undici
Hello, I’m Allie!
Workers doesn’t support threads or Undici, even with node_compat
user
userOP17mo ago
Oh. How could I use a proxy then? I was told I should use undici to send proxy requests with workers…
Hello, I’m Allie!
You can use proxies over HTTP(S)
user
userOP17mo ago
How so? I specifically need to be able to use auth with the proxy, so if cf can’t support that, i’m gonna have an issue xd
Hello, I’m Allie!
Nvm, I've apparently used a weird proxy. Looks like it should be able to work, but you may have to write your own proxy connector(since you have to use Workers' fetch rather than Undici), and you can't use threads.
user
userOP17mo ago
mmmm
Want results from more Discord servers?
Add your server