Skip to content

Bug e2b 2195 throws dynamic usage of require is not eng 4003#1323

Merged
matthewlouisbrockman merged 7 commits into
mainfrom
bug-e2b-2195-throws-dynamic-usage-of-require-is-not-eng-4003
May 11, 2026
Merged

Bug e2b 2195 throws dynamic usage of require is not eng 4003#1323
matthewlouisbrockman merged 7 commits into
mainfrom
bug-e2b-2195-throws-dynamic-usage-of-require-is-not-eng-4003

Conversation

@matthewlouisbrockman
Copy link
Copy Markdown
Contributor

@matthewlouisbrockman matthewlouisbrockman commented May 11, 2026

Fix the JS SDK envd HTTP/2 transport so it works in Next.js/Turbopack production builds.

The HTTP/2 path loaded undici through a dynamic require, which Turbopack rewrites to a runtime stub that throws during envd requests. This changes envd to load undici lazily at runtime through an import that bundlers cannot statically rewrite. If undici cannot be loaded, the SDK falls back to global fetch, so Node keeps the HTTP/2 dispatcher path when available without pulling undici into browser bundles.

tested node/next/browser

Load undici lazily through the existing dynamic import path so creating a sandbox does not hit Turbopack's dynamic require stub. Keep the Node HTTP/2 dispatcher setup for envd requests, including the capped REST client and uncapped RPC client.
Turbopack can bundle the literal import but rejects the shared dynamic import helper as too dynamic. Keep loading undici only on the Node envd path while letting Next resolve the module on the first request.
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has reached its monthly code review spending cap.

An organization admin can view or raise the cap at claude.ai/admin-settings/claude-code. The cap resets at the start of the next billing period.

Once the cap resets or is raised, reopen this pull request to trigger a review.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 11, 2026

🦋 Changeset detected

Latest commit: 17bb8bf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
e2b Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cla-bot cla-bot Bot added the cla-signed label May 11, 2026
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 11, 2026

ENG-4003

@cursor
Copy link
Copy Markdown

cursor Bot commented May 11, 2026

PR Summary

Medium Risk
Changes how the Node HTTP/2 transport loads undici and adds a fallback to global fetch, which could affect connection behavior and performance in Node runtimes if module loading differs.

Overview
Fixes Next.js/Turbopack production crashes in the JS SDK envd HTTP/2 path by removing the dynamic require('undici') and lazily loading undici via an opaque dynamic import() on first request.

Adds an optional loadUndici hook for injection/testing, and falls back to global fetch (with a one-time warning) when undici cannot be loaded; tests are updated to cover lazy loading and the fallback behavior.

Reviewed by Cursor Bugbot for commit 17bb8bf. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 11, 2026

Package Artifacts

Built from 0c15917. Download artifacts from this workflow run.

JS SDK (e2b@2.19.6-bug-e2b-2195-throws-dynamic-usage-of-require-is-not-eng-4003.0):

npm install ./e2b-2.19.6-bug-e2b-2195-throws-dynamic-usage-of-require-is-not-eng-4003.0.tgz

CLI (@e2b/cli@2.10.2-bug-e2b-2195-throws-dynamic-usage-of-require-is-not-eng-4003.0):

npm install ./e2b-cli-2.10.2-bug-e2b-2195-throws-dynamic-usage-of-require-is-not-eng-4003.0.tgz

Python SDK (e2b==2.21.0+bug-e2b-2195-throws-dynamic-usage-of-require-is-not-eng-4003):

pip install ./e2b-2.21.0+bug.e2b.2195.throws.dynamic.usage.of.require.is.not.eng.4003-py3-none-any.whl

Mark the envd undici import for bundlers to leave unresolved until runtime. The Node path still loads undici on first envd request, while Vite and Rspack web builds no longer try to bundle undici and its Node-only dependencies.
Hide the undici import from bundler static analysis and fall back to global fetch if it cannot be loaded. This keeps the HTTP/2 dispatcher path in Node without requiring a tsconfig module change or pulling undici into browser bundles.
Return the final envd fetch implementation from the loader instead of carrying an optional dispatcher envelope through the call site. The fallback path now reads as plain global fetch, while the undici path keeps dispatcher injection local.
@matthewlouisbrockman matthewlouisbrockman enabled auto-merge (squash) May 11, 2026 08:14
@matthewlouisbrockman matthewlouisbrockman merged commit b2a2786 into main May 11, 2026
45 of 49 checks passed
@matthewlouisbrockman matthewlouisbrockman deleted the bug-e2b-2195-throws-dynamic-usage-of-require-is-not-eng-4003 branch May 11, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: e2b 2.19.5 throws "dynamic usage of require is not supported" under Next.js 16 / Turbopack

2 participants