3

I am trying to use the date picker from react-toolbox.

Here is my webpack config:

    {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract('style-loader', 'css-loader!cssnext-loader')
    },{
        test: /\.scss$/,
        loaders: ['style', 'css', 'sass']
    }

I have .scss in the resolve section:

resolve: {
    extensions: ['', '.js', '.jsx', '.scss']
},

I have also wrapped my App component within ToolboxAPP

ReactDOM.render(
    <ToolboxApp>
        <Provider store={store}>
            <App />
        </Provider>
    </ToolboxApp>
, document.getElementById('root'))

When I rendered the component, here is what it looks like:

enter image description here

You can see from the image that the component is not styled, and the corresponding css class names are undefined.

Does anybody know what i did wrong?

Venugopal
  • 1,888
  • 1
  • 17
  • 30
Cheng
  • 16,824
  • 23
  • 74
  • 104

3 Answers3

2

You need to include modules (which unfortunately may break any other styling not using modules).

See https://github.com/react-toolbox/react-toolbox/issues/121 for more info.

This is the line you will need to utilize in your webpack loader:

require.resolve('css-loader') + '?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
mattgi
  • 712
  • 1
  • 7
  • 11
0

It looks like a Webpack config issue. It is actually weird because if webpack is not able to import the styles it should raise an import error instead of resolving an empty object. Since we cannot see the whole configuration file, I'd like to ask you if you already checked the working example repository: https://github.com/react-toolbox/react-toolbox-example

There is an example Webpack configuration, hope it helps!

javivelasco
  • 426
  • 3
  • 10
  • It imports styles on the page all right, it doesn't set classes. – Green Feb 09 '16 at 10:42
  • 1
    That webpack file is very confusing as someone who has a pretty simple webpack config file, a lot of the stuff in there doesn't seem specific to setting up for react-toolbox. – Alioo Feb 08 '17 at 22:57
0

its clear that webpack does not see the css/scss files, do you have any errors, if you look into that you will find the problem.

  1. problem might be that you need to install the css-loader and sass loader

    npm install css-loader --save-dev
    npm install sass-loader node-sass webpack --save-dev
    
  2. if you have done that try to resolve

    resolve: {extensions: ['', '.jsx', '.scss', '.js', '.json'],
        modulesDirectories: [
            'node_modules',
            ${process.cwd()}/node_modules
        ]
    },
    
  3. module: {
        loaders: [
            {
                test: /(\.js|\.jsx)$/,
                exclude: /(node_modules)/,
                loader: 'babel',
            },  {
                test: /(\.scss|\.css)$/,
                loader: ExtractTextPlugin.extract('style', 'css?sourceMap&modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss!sass'),
            },
            { test: /\.png$/, loader: "url-loader?limit=100000" },
            { test: /\.jpg$/, loader: "file-loader" },
        ]
    },
    
Tunaki
  • 132,869
  • 46
  • 340
  • 423
oshaiken
  • 2,593
  • 1
  • 15
  • 25
  • I had the similar problem and I have outlined steps to resolve the problem. 1. Is to make sure you install the correct loaders – oshaiken Feb 14 '16 at 19:02