Skip to content

Commit c62836c

Browse files
author
Bartek Wrona
committed
fixup! Replace require() with await import() in EXPORT_ES6 shell/runtime files
fixup! Replace require() with await import() in EXPORT_ES6 shell/runtime files Revert the bundler-hint removal from 548e32d. It was based on a mistaken assumption that webpack auto-handles `node:`-prefixed dynamic imports -- it does not. CI run on 548e32d hit: test_webpack_esm_output_clean: ERROR in node:fs Module build failed: UnhandledSchemeError: Reading from "node:fs" is not handled by plugins (Unhandled scheme). Webpack supports "data:" and "file:" URIs by default. You may need an additional plugin to handle "node:" URIs. Same error for node:path, node:url. All three show up because without `/* webpackIgnore: true */`, webpack attempts to resolve the dynamic import as a module and fails on the unknown scheme. Vite (per test/vite/vite.config.js) does auto-externalize `node:*` for browser -- emitting a warning that the config already whitelists -- so strictly speaking `/* @vite-ignore */` is optional. But we keep both for symmetry and to also silence vite's dynamic-import analysis noise. Updates the inline comment to explain the requirement so a future reader does not attempt the same simplification again. Addresses and supersedes the response to r3075818347 -- the hints cannot be removed unless we add a webpack plugin or drop support for webpack consumers of EXPORT_ES6 output.
1 parent 548e32d commit c62836c

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/parseTools.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,11 +962,12 @@ function makeNodeImport(module, guard = true) {
962962
// `await import` by `fix_js_mangling()` after Closure runs. See parseTools
963963
// preprocess() and tools/link.py fix_js_mangling().
964964
//
965-
// Bundlers (webpack 5, vite, rollup) auto-externalize `node:`-prefixed
966-
// dynamic imports for browser targets, so no per-call bundler hints are
967-
// needed here. test/vite/vite.config.js whitelists the resulting
968-
// "externalized for browser compatibility" warning.
969-
expr = `EMSCRIPTEN$AWAIT$IMPORT('${module}')`;
965+
// The `/* webpackIgnore: true */` hint is required because webpack does
966+
// NOT auto-handle `node:`-prefixed URIs for dynamic import; without it,
967+
// webpack fails with `UnhandledSchemeError: Reading from "node:xxx" is
968+
// not handled by plugins` (see test_webpack_esm_output_clean).
969+
// `/* @vite-ignore */` similarly silences vite's dynamic-import analysis.
970+
expr = `EMSCRIPTEN$AWAIT$IMPORT(/* webpackIgnore: true */ /* @vite-ignore */ '${module}')`;
970971
} else {
971972
expr = `require('${module}')`;
972973
}

0 commit comments

Comments
 (0)