Add bundler integration tests verifying EXPORT_ES6 output has no requ…#26419
Open
vogel76 wants to merge 1 commit intoemscripten-core:mainfrom
Open
Add bundler integration tests verifying EXPORT_ES6 output has no requ…#26419vogel76 wants to merge 1 commit intoemscripten-core:mainfrom
vogel76 wants to merge 1 commit intoemscripten-core:mainfrom
Conversation
sbc100
reviewed
Mar 9, 2026
…ire() Add two tests that verify EXPORT_ES6 output is valid ESM and works with bundlers: - test_webpack_esm_output_clean: Compiles with EXPORT_ES6 and default environment (web+node), then builds with webpack. On main, webpack hard-fails because it cannot resolve 'node:module' (used by emscripten's createRequire polyfill). This breaks any webpack/Next.js/Nuxt project. - test_vite_esm_output_clean: Compiles with EXPORT_ES6 and default environment, then builds with vite. On main, vite externalizes 'node:module' for browser compatibility, emitting a warning. The resulting bundle contains code referencing unavailable node modules. These tests are expected to fail on main and pass after eliminating require() from EXPORT_ES6 output.
dbc3947 to
de21f1e
Compare
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.
Summary
Adds two integration tests to
test_other.pythat demonstrate howrequire()calls inEXPORT_ES6output break bundlers. Both tests fail on main and are intended to pass after the require() elimination changes from #26384.This addresses the review comment requesting concrete test cases showing bundler breakage.
Tests added
test_webpack_esm_output_cleanCompiles with
-sEXPORT_ES6and default environment (web+node), then builds with webpack.Failure on main:
Why it fails: Emscripten's EXPORT_ES6 output uses
import { createRequire } from 'node:module'to polyfillrequire()for loading Node.js built-ins (fs,path,url). Webpack targeting web cannot resolvenode:URI schemes — it hard-errors and produces no bundle at all. This breaks any webpack-based project (including Next.js, Nuxt, and Create React App) that tries to use emscripten's ESM output.test_vite_esm_output_cleanCompiles with
-sEXPORT_ES6using default environment (web+node), then runsvite buildand checks for externalization warnings.Failure on main:
Why it fails: Vite encounters
import { createRequire } from 'node:module'in the ESM input. Since vite targets browsers, it can't bundle Node.js built-in modules. Instead of erroring, vite externalizesnode:module— the build succeeds but the resulting bundle contains code that references modules unavailable in browsers. While the hello_world test case works by accident (the node code path is guarded byif (ENVIRONMENT_IS_NODE)which is false in browsers), any application with more complex node/web interop would silently break.Rollup (not tested, for reference)
Rollup is the most lenient bundler — it warns about the unresolved dependency but still produces a bundle (exit code 0). The
require()calls are passed through as-is into the output:The resulting bundle contains 4
require()calls. In Node.js this works becausecreateRequireprovides a workingrequirefunction. In browsers the node code path is guarded byif (ENVIRONMENT_IS_NODE)so it's never reached — the bundle runs without error but carries dead node code. Because rollup doesn't error or even fail the build, it's a weaker test case and was not included in the test suite.Bundler behavior summary
UnhandledSchemeErroronnode:moduletest_webpack_esm_output_cleannode:modulefor browser compattest_vite_esm_output_cleanrequire()throughRelationship to #26384
These tests validate the fix in #26384 which replaces
require()withawait import()in EXPORT_ES6 output. After cherry-picking this commit onto that branch, both tests should pass.