Turbopack: report unsupported external modules as an issue - #97458
Draft
mischnic wants to merge 1 commit into
Draft
Turbopack: report unsupported external modules as an issue#97458mischnic wants to merge 1 commit into
mischnic wants to merge 1 commit into
Conversation
Importing a Node.js built-in from browser code, e.g. `import 'node:async_hooks'`
in `pages/_app.js`, failed with an unhelpful internal error:
Error [TurbopackInternalError]: Failed to write page endpoint /_app
Caused by:
- the chunking context (unknown) does not support external modules (request: node:async_hooks)
`node:async_hooks` is parsed as a URI request and resolved as an external, and
code generation for the ESM reference then bailed out because the browser
environment supports neither ESM nor CommonJS externals. That aborted writing
the whole endpoint and reported no source location.
Instead of bailing, emit a `CodeGenerationIssue` that points at the import (so
the code frame shows up in the overlay and the terminal) and generate an
expression that throws when the module is evaluated. Node.js built-ins get a
dedicated message:
node:async_hooks is a Node.js built-in module, which is not available in the
browser environment
Error issues are recoverable in dev and fatal in production builds, so
`next build` still fails, just with a useful message.
Also adds `Environment::name()` so messages can name the target environment
instead of the (usually unnamed) chunking context.
Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
Contributor
Stats from current PR🔴 1 regression
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
Build Cache
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URLCommit: 50e5d02 |
Contributor
Tests PassedCommit: 50e5d02 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Turbopack: report unsupported external modules as an issue instead of an internal error
What?
Replace the internal
turbobail!that Turbopack hit when an ESM reference resolvesto an external module the target environment can't load (e.g. a Node.js built-in
imported into browser code) with a proper Turbopack issue: an error-severity
CodeGenerationIssuepointing at the import, plus code that throws at runtimewhen the module is evaluated. Adds
Environment::name()so the message can namethe target environment (
browser,edge,Node.js) instead of the (usuallyunnamed) chunking context.
Why?
Importing a Node.js built-in from browser code, e.g.
import 'node:async_hooks'in
pages/_app.js, failed with:This looked like a Turbopack bug, gave no file/line, and aborted writing the
whole endpoint instead of surfacing a normal build error.