-
Notifications
You must be signed in to change notification settings - Fork 7
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 innext.config.js
to use the same file redirection thathttp-client
uses 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.js
application 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
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.