digitalbazaar / digitalbazaar/http-client
`undici` is leaking into browser environment
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 2
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
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.
Contributor guide
No contributing guide indexed for this repository
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.
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.
Assessment
- Tech stack
- javascript, next.js, typescript, webpack
- Domain
- build-system, tooling, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100