SCSS React library with swc fails to build
See original GitHub issueCurrent Behavior
I created a React UI library, which works ok in dev mode but fails to build.
It seems to be the scss modules are being treated as JS at some point, which should not be as they should be processed before by SASS.
Expected Behavior
I would expect the library to build without problems. Related content on: https://github.com/nrwl/nx/pull/2719
Steps to Reproduce
The setup I have is very minimal, two components in the lib: full-page-wrapper
and box
The styles for the first component are:
And the react component looks like this
I don’t include the second component for the sake of simplicity, but it’s also a very simple one. As you see I’m using a .modules.scss
file that is imported at the top of the component and then use the key full-page-wrapper
coming from the object it returns, that matches what I have in the scss
module.
I have tried using the styles
and stylePreprocessorOptions
options without luck. My project file looks like this:
Also added the assets to be compiled
When I’m working on another app that is connected to this React library in development mode, I have no issue whatsoever and it’s very fast. When I build I see the error shown at the top of this issue.
Failure Logs
Environment
Windows 11
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6
I found another way of reproducing.
css
file generatedAfter testing several times, I found using the
swc
compiler produces the issue. Usingbabel
this does not happen, although it loses the obvious advantage of faster compilation.seems like this is no longer an issue when I bump NX version to
14.8.1
. (I have not extensively tested which version gets rid of this issue, but I previously was experiencing this issue in NX version14.3.x
)