Skip to content

Commit 0d253df

Browse files
justin808claude
andcommitted
Fix webpack SCSS rule handling for Shakapacker 9.1.0
Shakapacker 9.1.0 changed how webpack rules are structured. The findIndex approach was failing because it returned -1 when no SCSS rule was found, causing "Cannot read properties of undefined". Updated to use forEach pattern (matching main spec/dummy) which: - Safely iterates through all rules - Checks if rule.use is an array before accessing it - Handles multiple SCSS rules if present This fixes the build error: "TypeError: Cannot read properties of undefined (reading 'push')" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1370dcf commit 0d253df

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

react_on_rails_pro/spec/dummy/config/webpack/commonWebpackConfig.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ const sassLoaderConfig = {
2626
};
2727

2828
const baseClientWebpackConfig = generateWebpackConfig();
29-
const scssConfigIndex = baseClientWebpackConfig.module.rules.findIndex((config) =>
30-
'.scss'.match(config.test),
31-
);
32-
baseClientWebpackConfig.module.rules[scssConfigIndex].use.push(sassLoaderConfig);
29+
30+
// Add sass-resources-loader to all SCSS rules
31+
baseClientWebpackConfig.module.rules.forEach((rule) => {
32+
if (Array.isArray(rule.use) && rule.test && '.scss'.match(rule.test)) {
33+
rule.use.push(sassLoaderConfig);
34+
}
35+
});
3336

3437
if (isHMR) {
3538
baseClientWebpackConfig.plugins.push(

0 commit comments

Comments
 (0)