From 4755f5df91e71a3a08d8c8aa4d82cb4eabf6ade4 Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 27 May 2024 18:10:36 +0800 Subject: [PATCH] fix: browserslist resolve is broken by prebundle (#6629) --- packages/rspack/prebundle.config.mjs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/rspack/prebundle.config.mjs b/packages/rspack/prebundle.config.mjs index 9fa79d2b4a3..c14e9ea67f1 100644 --- a/packages/rspack/prebundle.config.mjs +++ b/packages/rspack/prebundle.config.mjs @@ -22,6 +22,18 @@ export default { externals: { "caniuse-lite": "caniuse-lite", "/^caniuse-lite(/.*)/": "caniuse-lite$1" + }, + // preserve the `require(require.resolve())` + beforeBundle(task) { + const nodeFile = join(task.depPath, "node.js"); + const content = readFileSync(nodeFile, "utf-8"); + writeFileSync( + nodeFile, + content.replaceAll( + "require(require.resolve", + 'eval("require")(require.resolve' + ) + ); } }, {