Skip to content

Commit 548e32d

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 Drop the per-call `/* webpackIgnore: true */ /* @vite-ignore */` directives from makeNodeImport's generated `await import(...)` expression. Reviewer question (r3075818347): "I won't love having this vender/bundler-specific comments in the code like this. Didn't you say that these bundlers should automatically ignore things with the 'node:' prefix?" Modern webpack 5, vite, and rollup auto-externalize `node:`-prefixed dynamic imports for browser targets. The hints only suppress a "externalized for browser compatibility" warning, which test/vite/vite.config.js already whitelists explicitly for node:* modules. Correctness is unchanged whether the hints are present or not. Verified locally: - other.test_esm_no_require (3 variants) passes. - emcc -sEXPORT_ES6 -sMODULARIZE produces clean `await import('node:fs')` / `node:path` / `node:url` calls with no bundler-specific comment blocks in the output.
1 parent f9a9bc8 commit 548e32d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/parseTools.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,12 @@ function makeNodeImport(module, guard = true) {
961961
// for hand-written `await import` calls in source files. It is restored to
962962
// `await import` by `fix_js_mangling()` after Closure runs. See parseTools
963963
// preprocess() and tools/link.py fix_js_mangling().
964-
expr = `EMSCRIPTEN$AWAIT$IMPORT(/* webpackIgnore: true */ /* @vite-ignore */ '${module}')`;
964+
//
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}')`;
965970
} else {
966971
expr = `require('${module}')`;
967972
}

0 commit comments

Comments
 (0)