`undici` is leaking into browser environment
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, next.js, typescript, webpack
- Domain
- build-system, tooling, web-dev
Research direction
Start with the browser-compatible export provisions in package.json and compare them with the import trace produced by next dev. Then inspect the referenced next.config.js, tsconfig.json, and rollup.config.js alongside agentCompatibility.js and agentCompatibility-browser.js. Done means a TypeScript and Next.js browser build no longer resolves the undici dependency through the server path.
Written by the indexing model from the issue text.
Description
Description
@dmitrizagidulin and I have been investigating an issue importing http-client into a browser context. The issue is coming from the undici library, which is not compatible with the browser. We noticed that there are provisions in the package.json to exclude problematic files from browser-compatible exports, but it does not seem to fix the issue. We are indirectly using this library as a second-order dependency in a TypeScript + Next.js application, but it seems we will need to make modifications to this library to get it to work.
Solutions tried
- Overriding the
webpackrules innext.config.jsto use the same file redirection thathttp-clientuses in itspackage.json - Instructing TypeScript (via
tsconfig.json) to use the same file replacement ashttp-client:{ "compilerOptions": { "baseUrl": "./", "paths": { "@digitalbazaar/http-client/lib/agentCompatibility.js": ["node_modules/@digitalbazaar/http-client/lib/agentCompatibility-browser.js"], "@digitalcredentials/security-document-loader/node_modules/@digitalbazaar/http-client/lib/agentCompatibility.js": ["node_modules/@digitalbazaar/http-client/lib/agentCompatibility-browser.js"] } } - Modifying environment-based export directives in
package.json - Modifying configuration in
rollup.config.js
Reproduction steps
- Install application in a
TypeScript+Next.jsapplication with different combinations of solutions listed above - Run
next dev - Observe error
Error stack
This is the undici error:
This is the import trace (you'll notice that agentCompatibility.js was not replaced by agentCompatibility-browser.js, as specified in package.json):
Tooling
TypeScriptNext.js
Next steps
We think the best approach will involve a direct PR to this repo that fixes browser exports in this setup.
- Dominant language
- JavaScript
- Stars
- 2
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from digitalbazaar/http-client
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
digitalbazaar/http-client#44 ·
-
Keep an eye on `node:undici` (or similar) exposing `undici` in `node` and remove `undici` dependencyOpen
Difficulty 3/5 1-2 days Newbie friendliness 30/100
digitalbazaar/http-client#43 ·
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
digitalbazaar/http-client#37 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
digitalbazaar/http-client#33 ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
digitalbazaar/http-client#30 · 1 comment ·
All issues in digitalbazaar/http-client
Similar issues
-
clawsweeper:needs-product-decision clawsweeper:needs-security-review clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:security issue-rating: 🦞 diamond lobster P2
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openclaw/openclaw#166870 · 2 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
⚠ needs intervention document structure changed
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Bug pulumi/pulumi
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
uoftblueprint/canada-basketball#32 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
andromarces/agent-loops#571 ·
Maintainers usually reply within 1 day