Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

`undici` is leaking into browser environment

Open
#45 1 comment 0 reactions 0 assignees View on GitHub

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

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 webpack rules in next.config.js to use the same file redirection that http-client uses in its package.json
  • Instructing TypeScript (via tsconfig.json) to use the same file replacement as http-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.js application with different combinations of solutions listed above
  • Run next dev
  • Observe error
Error stack

This is the undici error:

Screenshot 2024-03-18 at 5 54 01 PM

This is the import trace (you'll notice that agentCompatibility.js was not replaced by agentCompatibility-browser.js, as specified in package.json):

Screenshot 2024-03-18 at 5 55 54 PM

Tooling
  • TypeScript
  • Next.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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from digitalbazaar/http-client

All issues in digitalbazaar/http-client

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.