diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/provide_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/provide_dependency.rs index 65fad19679c..8ceacb6f463 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/provide_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/provide_dependency.rs @@ -92,7 +92,8 @@ impl DependencyTemplate for ProvideDependency { } = code_generatable_context; let module_graph = compilation.get_module_graph(); let Some(con) = module_graph.connection_by_dependency(&self.id) else { - unreachable!(); + // not find connection, maybe because it's not resolved in make phase, and `bail` is false + return; }; let exports_info = module_graph.get_exports_info(con.module_identifier()); let used_name = diff --git a/packages/rspack-test-tools/tests/configCases/builtins/provide-not-resolved/errors.js b/packages/rspack-test-tools/tests/configCases/builtins/provide-not-resolved/errors.js new file mode 100644 index 00000000000..86e9297b88f --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/builtins/provide-not-resolved/errors.js @@ -0,0 +1,3 @@ +module.exports = [ + /Can't resolve 'not-exist'/ +] diff --git a/packages/rspack-test-tools/tests/configCases/builtins/provide-not-resolved/index.js b/packages/rspack-test-tools/tests/configCases/builtins/provide-not-resolved/index.js new file mode 100644 index 00000000000..7e79053af59 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/builtins/provide-not-resolved/index.js @@ -0,0 +1,5 @@ +try { + foo; +} catch (_) { + +} diff --git a/packages/rspack-test-tools/tests/configCases/builtins/provide-not-resolved/rspack.config.js b/packages/rspack-test-tools/tests/configCases/builtins/provide-not-resolved/rspack.config.js new file mode 100644 index 00000000000..ce4c39f1c89 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/builtins/provide-not-resolved/rspack.config.js @@ -0,0 +1,13 @@ +const { rspack } = require("@rspack/core"); + +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + entry: { + main: ["./index.js"] + }, + plugins: [ + new rspack.ProvidePlugin({ + foo: "not-exist", + }) + ], +};