4

Everything seems fine, there are no errors, but elements on the page are still not styled.

webpack.config.js

{
    test: /\.css$/,
    loader: ExtractTextPlugin.extract('style', 'css?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]')
},


plugins: [
  new ExtractTextPlugin('app.css', {
    allChunks: true
  }),
],

Layout.js

import React, { Component } from 'react';
import InteractiveMap from './InteractiveMap';
import Header from './header';
import Navigation from './navigation';
import CSSModules from 'react-css-modules';
import styles from './Layout.css';

class Layout extends Component {
  render() {
    return (
      <div>
        <div className={styles.mapContainer}>
         <InteractiveMap /> 
       </div>
       <div>
         <Header className={styles.header}>
            <Navigation menuItems={menuItems}/>
         </Header>
        </div>
      </div>
    );
  }
}

export default CSSModules(Layout, styles);

Layout.css

//testing

.mapContainer: {
    padding: 0;
    background-color: black;
    height: 100%;
    color: yellow;
}

.header {
    color: yellow;
    background-color: blue;
}

compiled app.css

.Layout__mapContainer___3yH5h: {
  padding: 0;
  background-color: black;
  height: 100%;
  color: yellow;
}

.Layout__header___2kJ4F {
    color: yellow;
    background-color: blue;
}

As you can see on the picture, classes are generated, applied to elements, but on the page nothing is showing. image

1
  • 1
    Have you got any solution for this? I am facing the same issue. Commented Jun 5, 2017 at 12:31

3 Answers 3

1

In react-css-modules you use styleName instead of className:

<div styleName="container">

This should work:

class Layout extends Component {
  render() {
    return (
      <div>
        <div styleName="mapContainer">
         <InteractiveMap /> 
       </div>
       <div>
         <Header styleName="header">
            <Navigation menuItems={menuItems}/>
         </Header>
        </div>
      </div>
    );
  }
}
Sign up to request clarification or add additional context in comments.

7 Comments

Yes, I've tried it already, but unfortunately it doesn't work
What do you get when you do console.log(styles)?
I get an object: Object {mapContainer: Layout__mapContainer___3yH5h", header: "Layout__header___2kJ4F"}
And does it work without the extractTextPlugin? If it does work without the plugin, it means that you haven't included a reference to app.css in your html file.
Added the compiled css file. Here's reference in my html: <link rel="stylesheet" href="app.css">. Also it's not working without the extractTextPlugin and in console it shows error: GET http://localhost:8080/app.css. Could the problem be the wrong path to css file? I tried changing it different ways, but can't figure it out.
|
0

I was having the same issue.. my problem was that I did not include the generated css stylesheet in my .html file.

Without the stylesheet

<html>
<head>
</head>

<body>
    <div id = "hero"> </div>
    <script type="text/javascript" src="bundle.js"></script>
</body>

With the stylesheet (fix)

<html>
<head>
     <link rel='stylesheet' href='app.css'>
</head>

<body>
    <div id = "hero"> </div>
    <script type="text/javascript" src="bundle.js"></script>
</body>

Comments

0

You need added prefix "module", example:

import styles from './Layout.module.css';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.