diff --git a/crates/rspack_core/src/compilation/mod.rs b/crates/rspack_core/src/compilation/mod.rs index 6313b6e995c9..68c8d3bf5587 100644 --- a/crates/rspack_core/src/compilation/mod.rs +++ b/crates/rspack_core/src/compilation/mod.rs @@ -1292,6 +1292,7 @@ impl Compilation { )); chunks } else { + self.chunk_render_artifact.clear(); self.chunk_by_ukey.keys().copied().collect() }; let results = rspack_futures::scope::<_, Result<_>>(|token| { @@ -1850,6 +1851,7 @@ impl Compilation { modules } else { + self.cgm_hash_artifact.clear(); self.get_module_graph().modules().keys().copied().collect() }; self @@ -1889,6 +1891,7 @@ impl Compilation { )); modules } else { + self.code_generation_results = Default::default(); self.get_module_graph().modules().keys().copied().collect() }; self.code_generation(code_generation_modules).await?; @@ -1931,6 +1934,7 @@ impl Compilation { )); modules } else { + self.cgm_runtime_requirements_artifact = Default::default(); self.get_module_graph().modules().keys().copied().collect() }; self @@ -1972,6 +1976,7 @@ impl Compilation { )); affected_chunks } else { + self.cgc_runtime_requirements_artifact.clear(); self.chunk_by_ukey.keys().copied().collect() }; self @@ -2372,6 +2377,7 @@ impl Compilation { )); chunks } else { + self.chunk_hashes_artifact.clear(); self.chunk_by_ukey.keys().copied().collect() }; diff --git a/tests/rspack-test/watchCases/recover-from-error/delete-file/0/file.js b/tests/rspack-test/watchCases/recover-from-error/delete-file/0/file.js new file mode 100644 index 000000000000..46c7130a8a1f --- /dev/null +++ b/tests/rspack-test/watchCases/recover-from-error/delete-file/0/file.js @@ -0,0 +1 @@ +module.exports = 'ok'; diff --git a/tests/rspack-test/watchCases/recover-from-error/delete-file/0/index.js b/tests/rspack-test/watchCases/recover-from-error/delete-file/0/index.js new file mode 100644 index 000000000000..0cc4b5bbb95b --- /dev/null +++ b/tests/rspack-test/watchCases/recover-from-error/delete-file/0/index.js @@ -0,0 +1,15 @@ +it('should recover when recreate file', function () { + switch (WATCH_STEP) { + case '0': + expect(require('./file')).toBe('ok'); + break; + case '1': + expect(function () { + require('./file'); + }).toThrow(); + break; + case '2': + expect(require('./file')).toBe('ok'); + break; + } +}); diff --git a/tests/rspack-test/watchCases/recover-from-error/delete-file/1/errors.js b/tests/rspack-test/watchCases/recover-from-error/delete-file/1/errors.js new file mode 100644 index 000000000000..5608e5447bfd --- /dev/null +++ b/tests/rspack-test/watchCases/recover-from-error/delete-file/1/errors.js @@ -0,0 +1 @@ +module.exports = [/Module not found: Can't resolve/]; diff --git a/tests/rspack-test/watchCases/recover-from-error/delete-file/1/file.js b/tests/rspack-test/watchCases/recover-from-error/delete-file/1/file.js new file mode 100644 index 000000000000..f42a9f0e7e14 --- /dev/null +++ b/tests/rspack-test/watchCases/recover-from-error/delete-file/1/file.js @@ -0,0 +1 @@ +DELETE diff --git a/tests/rspack-test/watchCases/recover-from-error/delete-file/2/file.js b/tests/rspack-test/watchCases/recover-from-error/delete-file/2/file.js new file mode 100644 index 000000000000..46c7130a8a1f --- /dev/null +++ b/tests/rspack-test/watchCases/recover-from-error/delete-file/2/file.js @@ -0,0 +1 @@ +module.exports = 'ok'; diff --git a/tests/rspack-test/watchCases/recover-from-error/delete-file/rspack.config.js b/tests/rspack-test/watchCases/recover-from-error/delete-file/rspack.config.js new file mode 100644 index 000000000000..5e67dfe8e2d3 --- /dev/null +++ b/tests/rspack-test/watchCases/recover-from-error/delete-file/rspack.config.js @@ -0,0 +1,7 @@ +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + ignoreWarnings: [/FlagDependencyUsagePlugin/], + optimization: { + usedExports: true, + }, +};