Replies: 5 comments
-
hi @darkula, I think this is probably a css-loader config issue. Anyway, just shoot me a repo and I'll help debug it. |
Beta Was this translation helpful? Give feedback.
-
hi @xiaoxiaojx unfortunately I can`t share repo (private), but I can provide debug info from css-loader. What information do you need from css-loader? |
Beta Was this translation helpful? Give feedback.
-
@darkula We need a minimal reproduction repo. Please try to create one using CRA or webpack-cli if possible. |
Beta Was this translation helpful? Give feedback.
-
@xiaoxiaojx here you go: |
Beta Was this translation helpful? Give feedback.
-
@darkula I recommend following the official example for the import. You can modify your code like this: + import "react-datepicker/dist/react-datepicker.css";
- import "react-datepicker/src/stylesheets/datepicker.scss"
If you still prefer to keep your current import style (e.g. importing SCSS directly), you can adjust your webpack.config.js like this to ensure those styles aren't tree-shaken: module.exports = {
// ... your existing config
module: {
rules: [
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
// Mark SCSS files as having side effects
+ sideEffects: true
}
]
}
};
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
After upgrading from Webpack 3 to Webpack 5 I'm facing an issue where SCSS files from node_modules are not being properly loaded in my React project. When I try to import a SCSS file like
import "react-datepicker/src/stylesheets/datepicker.scss";
the styles are not injected into index.html. This might be due to issues with SCSS handling or CSS Modules configuration in my Webpack setup.Here is how I’m importing SCSS in my React component:
if I import the same SCSS file in this way, then styles are injected in index.html:
or
if I copy
node_modules/react-datepicker/src/stylesheets/datepicker.scss
to project src, then styles are injected in index.htmlHere is my Webpack after updating to v5 version:
Simple project structure
import "react-datepicker/src/stylesheets/datepicker.scss";
)node_modules/react-datepicker/src/stylesheets/datepicker.scss
)Beta Was this translation helpful? Give feedback.
All reactions