Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rebuild ignore modules contain built-in loader errors #9482

Merged
merged 2 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/rspack_core/src/normal_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,15 @@ impl Module for NormalModule {
.with_stack(stack)
.with_hide_stack(captured_error.hide_stack)
} else {
self.build_info.cacheable = false;
if let Some(file_path) = &self.resource_data.resource_path {
if file_path.is_absolute() {
self
.build_info
.file_dependencies
.insert(file_path.clone().into_std_path_buf().into());
}
}
let node_error = r.downcast_ref::<NodeError>();
let stack = node_error.and_then(|e| e.stack.clone());
let hide_stack = node_error.and_then(|e| e.hide_stack);
Expand Down
31 changes: 31 additions & 0 deletions tests/e2e/cases/make/failed_module_by_builtin_loader/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect, test } from "@/fixtures";

test("should compile", async ({ page, fileAction, rspack }) => {
await expect(page.getByText("index")).toBeVisible();

fileAction.updateFile("src/index.js", content =>
content.replace('div.innerText = "index";', 'div.innerText = "er;')
);

await page.reload();
await expect(page.locator("#webpack-dev-server-client-overlay")).toHaveCount(
1
);
let stats = rspack.compiler._lastCompilation
?.getStats()
.toJson({ all: false, errors: true });
expect(stats?.errors?.length).toBe(1);

fileAction.updateFile("src/index.js", content =>
content.replace('div.innerText = "er;', 'div.innerText = "index";')
);
await page.reload();
await expect(page.locator("#webpack-dev-server-client-overlay")).toHaveCount(
0
);
await expect(page.getByText("index")).toBeVisible();
stats = rspack.compiler._lastCompilation
?.getStats()
.toJson({ all: false, errors: true });
expect(stats?.errors?.length).toBe(0);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const rspack = require("@rspack/core");

/** @type {import("@rspack/core").Configuration} */
module.exports = {
entry: "./src/index.js",
context: __dirname,
mode: "development",
plugins: [new rspack.HtmlRspackPlugin()],
module: {
rules: [
{
test: /\.js$/,
exclude: [/node_modules/],
include: [/src/],
loader: "builtin:swc-loader"
}
]
},
devServer: {
hot: true
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Promise.resolve().then(() => {
const div = document.createElement("div");
div.innerText = "index";
div.id = "index";
document.body.appendChild(div);
});
31 changes: 31 additions & 0 deletions tests/e2e/cases/make/failed_module_by_js_loader/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect, test } from "@/fixtures";

test("should compile", async ({ page, fileAction, rspack }) => {
await expect(page.getByText("index")).toBeVisible();

fileAction.updateFile("src/index.js", content =>
content.replace('div.innerText = "index";', 'div.innerText = "error";')
);

await page.reload();
await expect(page.locator("#webpack-dev-server-client-overlay")).toHaveCount(
1
);
let stats = rspack.compiler._lastCompilation
?.getStats()
.toJson({ all: false, errors: true });
expect(stats?.errors?.length).toBe(1);

fileAction.updateFile("src/index.js", content =>
content.replace('div.innerText = "error";', 'div.innerText = "index";')
);
await page.reload();
await expect(page.locator("#webpack-dev-server-client-overlay")).toHaveCount(
0
);
await expect(page.getByText("index")).toBeVisible();
stats = rspack.compiler._lastCompilation
?.getStats()
.toJson({ all: false, errors: true });
expect(stats?.errors?.length).toBe(0);
});
6 changes: 6 additions & 0 deletions tests/e2e/cases/make/failed_module_by_js_loader/loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function (content) {
if (content.includes("error")) {
throw new Error("loader transform error");
}
return content;
};
22 changes: 22 additions & 0 deletions tests/e2e/cases/make/failed_module_by_js_loader/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const rspack = require("@rspack/core");

/** @type {import("@rspack/core").Configuration} */
module.exports = {
entry: "./src/index.js",
context: __dirname,
mode: "development",
plugins: [new rspack.HtmlRspackPlugin()],
module: {
rules: [
{
test: /\.js$/,
exclude: [/node_modules/],
include: [/src/],
loader: "./loader.js"
}
]
},
devServer: {
hot: true
}
};
6 changes: 6 additions & 0 deletions tests/e2e/cases/make/failed_module_by_js_loader/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Promise.resolve().then(() => {
const div = document.createElement("div");
div.innerText = "index";
div.id = "index";
document.body.appendChild(div);
});
Loading