i got a empty object when import a sass file.
See original GitHub issuehi, brother. i saw many tutorial import css file like this:
import React, { PropTypes, Component } from 'react'
import styles from './index.css'
console.log(styles)
export default class PageLoading extends Component {
render() {
return (
<div className={styles.loading}>Hello page loading!</div>
)
}
}
please attention the className is expression. but when i import sass by same way. i found i can’t use the styles.loading in className
import React, { PropTypes, Component } from 'react'
import styles from './index.scss'
console.log(styles)
// styles is a empty object
export default class PageLoading extends Component {
render() {
return (
<div className={styles.loading}>Hello page loading!</div>
)
}
}
how can i resolve it. thank u.!
Issue Analytics
- State:
- Created 8 years ago
- Reactions:7
- Comments:11
Top Results From Across the Web
React - Importing non-modular sass file returns empty object
When importing the other one, I get an empty object. The two scss files are identical. Here's my scss file: :export { a:...
Read more >дэн on Twitter: "@jon_raRaRa What do you mean by "empty ...
Duh, of course! First impression is that I'm not able to import SCSS files in components, they're just empty objects. Upgraded to react-scripts...
Read more >css-loader not importing .css file returning empty object-Reactjs
Coding example for the question css-loader not importing .css file returning empty object-Reactjs.
Read more >empty - CSS: Cascading Style Sheets - MDN Web Docs
The :empty CSS pseudo-class represents any element that has no children. Children can be either element nodes or text (including whitespace) ...
Read more >mixin and @include - Sass
Mixins allow you to define styles that can be re-used throughout your stylesheet. They make it easy to avoid using non-semantic classes like...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is not a sass-loader issue, you just forgot to turn on CSS Modules in the css-loader.
For anyone else finding this topic years later, the CSS Modules config is important as noted in the previous comment.
The simple fix, without really needing to adjust the default
modules
config forcss-loader
is to put.module.
into your file name. E.g.:_exports.module.scss
This allows the CSS Loader to automagically determine this is a module, and now your
:export
variables will be picked up correctly in JS import.