Too long; Didn't read
I'm facing an issue where the css file I import into a typescript module resolves to a string instead of an object. Can someone help me understand why this is happening?
For Instance
// preview.ts
import test from './src/assets/test.theme.css';
// also tried this:
// import * as test from './src/assets/test.theme.css';
console.log('typeof test: ', typeof test);
console.log(test);
What's displayed on the console: https://i.stack.imgur.com/j30hP.png
In-depth Explanation
Currently, I am setting up a Storybook for my Angular12 component library.
To provide different themes, I intend to utilize the
plugin, which mentions the inline loader syntax of Webpack in its documentation.@etchteam/storybook-addon-css-variables-theme
import myTheme from '!!style-loader?injectType=lazyStyleTag!css-loader!./assets/my-theme.css';
Upon implementing this in my code, my browser console started throwing errors
Error: myTheme.use is not a function
While investigating, I discovered that the imported stylesheet isn't an evaluated javascript object but rather a string containing the source code created by the style-loader.
I also found that this issue extends beyond the style-loader and applies to other loaders like css-loader, raw-loader, etc.
This problem isn't limited to the inline loader syntax and also occurs with loaders defined in a basic webpack configuration.
Environment details:
- Angular 12
- Webpack 5
Replication
I have created a GIT repository demonstrating the problem.
The readme file explains how to reproduce the issue.