diff --git a/crates/node_binding/binding.d.ts b/crates/node_binding/binding.d.ts index 37ae507b5d08..8e09c5bdde86 100644 --- a/crates/node_binding/binding.d.ts +++ b/crates/node_binding/binding.d.ts @@ -222,7 +222,7 @@ export declare class JsModule { get nameForCondition(): string | undefined get request(): string | undefined get userRequest(): string | undefined - set userRequest(val: string) + set userRequest(val: string | undefined) get rawRequest(): string | undefined get factoryMeta(): JsFactoryMeta | undefined get type(): string diff --git a/crates/rspack_binding_values/src/module.rs b/crates/rspack_binding_values/src/module.rs index 7132f4dd4322..e2da91fb6eba 100644 --- a/crates/rspack_binding_values/src/module.rs +++ b/crates/rspack_binding_values/src/module.rs @@ -135,11 +135,15 @@ impl JsModule { } #[napi(setter)] - pub fn set_user_request(&mut self, val: String) -> napi::Result<()> { - let module: &mut dyn Module = self.as_mut()?; - - if let Ok(normal_module) = module.try_as_normal_module_mut() { - *normal_module.user_request_mut() = val; + pub fn set_user_request(&mut self, val: Either) -> napi::Result<()> { + match val { + Either::A(val) => { + let module: &mut dyn Module = self.as_mut()?; + if let Ok(normal_module) = module.try_as_normal_module_mut() { + *normal_module.user_request_mut() = val; + } + } + Either::B(_) => {} } Ok(()) } diff --git a/packages/rspack/src/Module.ts b/packages/rspack/src/Module.ts index c3f7941587d8..29fa2fe1e11f 100644 --- a/packages/rspack/src/Module.ts +++ b/packages/rspack/src/Module.ts @@ -271,8 +271,10 @@ export class Module { get(): string | undefined { return module.userRequest; }, - set(val: string) { - module.userRequest = val; + set(val: string | undefined) { + if (val) { + module.userRequest = val; + } } }, rawRequest: {