question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

i got a empty object when import a sass file.

See original GitHub issue

hi, 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:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:11

github_iconTop GitHub Comments

35reactions
silvenoncommented, Mar 8, 2016

This is not a sass-loader issue, you just forgot to turn on CSS Modules in the css-loader.

23reactions
Drumstix42commented, May 26, 2021

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 for css-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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found