Skip to content

Fix CSS Modules compatibility with Shakapacker 9.0.0+ #1957

@justin808

Description

@justin808

Summary

Fix CSS Modules compatibility issues with Shakapacker 9.0.0+ to ensure existing import patterns continue to work.

Problem

Shakapacker 9.0+ defaults to namedExport: true for CSS Modules, which breaks existing code using:

import styles from './file.module.css'

This causes errors because named exports expect:

import * as styles from './file.module.css'

Proposed Solution

1. Configure CSS Modules for Backward Compatibility

Update webpack config to set:

loader.options.modules.namedExport = false;
loader.options.modules.exportLocalsConvention = 'camelCase';

2. Fix SCSS Variable Issues

  • Import app-variables in CSS Module files to prevent undefined variable errors
  • Remove redundant @import statements
  • Update both OSS and Pro dummy apps

3. Update Documentation

  • Document CSS Modules configuration for Shakapacker 9+
  • Add migration guide for upgrading projects
  • Include troubleshooting section

Files to Update

From PR #1896 as reference:

  • spec/dummy/config/webpack/commonWebpackConfig.js
  • react_on_rails_pro/spec/dummy/config/webpack/commonWebpackConfig.js
  • spec/dummy/client/app/components/HelloWorld.module.scss
  • react_on_rails_pro/spec/dummy/client/app/components/HelloWorld.module.scss
  • CSS Modules documentation

Testing

  • Test existing CSS Module imports work
  • Verify SCSS variables are resolved
  • Test in both OSS and Pro dummy apps
  • Ensure no console errors or warnings

Related

Labels

bug, enhancement

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions