-1

I added the rc-range-slider package to my project and started getting the error messages listed in the next paragraph when I tried to compile my react project using Webpack ^2.5.1. The suggested webpack config in the NPM site for this slider is compatible with the previous versions of webpack. The Webpack configuration in the last paragraph below is my attempt to fit it into the new Webpack configuration constraints. But I am getting the following error messages:

Please see a demo at Github

ERROR in ./~/css-loader!./~/postcss-loader/lib!./~/rc-range-slider/lib/Slider/slider.css
Module build failed: Error: No PostCSS Config found in: \js\node_modules\rc-range-slider\lib\Slider
    at Error (native)
    at \js\node_modules\postcss-load-config\index.js:51:26
 @ ./~/style-loader!./~/css-loader!./~/postcss-loader/lib!./~/rc-range-slider/lib/Slider/slider.css 4:14-105 18:2-22:4 19:20-111
 @ ./~/rc-range-slider/lib/Slider/slider.css
 @ ./~/rc-range-slider/lib/Slider/index.js
 @ ./~/rc-range-slider/lib/index.js
 @ ./src/search-component.jsx
 @ ./src/search-component.jsx
 @ ./src/search-container.js
 @ ./src/routes.js
 @ ./src/index.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server babel-polyfill webpack-dev-server/client?http://localhost:8080 webpack/hot/only-dev-server ./src/index.js

ERROR in ./~/css-loader!./~/postcss-loader/lib!./~/rc-tipso/lib/Tipso/BaseTipso/base_tipso.css
Module build failed: Error: No PostCSS Config found in: \js\node_modules\rc-tipso\lib\Tipso\BaseTipso
    at Error (native)
    at \js\node_modules\postcss-load-config\index.js:51:26
 @ ./~/style-loader!./~/css-loader!./~/postcss-loader/lib!./~/rc-tipso/lib/Tipso/BaseTipso/base_tipso.css 4:14-115 18:2-22:4 19:20-121
 @ ./~/rc-tipso/lib/Tipso/BaseTipso/base_tipso.css
 @ ./~/rc-tipso/lib/Tipso/BaseTipso/index.js
 @ ./~/rc-tipso/lib/Tipso/index.js
 @ ./~/rc-tipso/lib/index.js
 @ ./~/rc-range-slider/lib/Slider/Dragger.js
 @ ./~/rc-range-slider/lib/Slider/index.js
 @ ./~/rc-range-slider/lib/index.js
 @ ./src/search-component.jsx
 @ ./src/search-component.jsx
 @ ./src/search-container.js
 @ ./src/routes.js
 @ ./src/index.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server babel-polyfill webpack-dev-server/client?http://localhost:8080 webpack/hot/only-dev-server ./src/index.js
webpack: Failed to compile.

Below is my webpack configuration:

var webpack = require( 'webpack' ),
    merge = require( 'lodash/merge' ),
    ExtractTextPlugin = require( 'extract-text-webpack-plugin' ),
    hotModuleReplacement = new webpack.HotModuleReplacementPlugin(),
    constants = {
            process:{
                env: {
                    NODE_ENV: JSON.stringify( 'development' )
                }
            }
        },
    extractSass = new ExtractTextPlugin({
            allChunks: true,
            disable: constants.process.env.NODE_ENV !== 'development',
            filename: 'public/main.css'
        }),
    getStylesheets = function( ...names ){
            const options = {
                    data: '$env: ' + constants.process.env.NODE_ENV + ';',
                    includePaths: [ 'res/main', 'node_modules' ],
                    sourceMap: true
                  },
                  specifics = {
                    css: {
                        modules: true,
                        importLoaders: 1,
                        localIdentName: '[name]__[local]___[hash:base64:5]',
                    },
                    postcss: {
                        postcss: () => [ 
                            require( 'postcss-import' )({ 
                                    addDependencyTo: webpack 
                                }),
                            require( 'postcss-url' )(),
                            require( 'postcss-cssnext' )(),
                                  // add your <plugins> here
                                  // ...
                                  // and if you want to compress,
                                  // just use css-loader option that already use cssnano under the hood
                            require( 'postcss-browser-reporter' )(),
                            require( 'postcss-reporter' )()
                        ]
                    },
                  };
            return names.map( 
                    constants.process.env.NODE_ENV ?
                    n => ({ loader: n + '-loader' }) : 
                    n => ({ loader: n + '-loader', options: merge( {}, options, ( specifics[ n ] | {} ))}));
        },
    getJSX = ( ...names ) => 
        names.map( n => ({
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: n + '-loader',
            query: {
                plugins: [ 'transform-decorators-legacy', 'transform-runtime' ],
                presets: [ 'latest', 'react', 'airbnb' ]
            }
        }));

module.exports = {
    entry: [
        'babel-polyfill',
        'webpack-dev-server/client?http://localhost:8080',
        'webpack/hot/only-dev-server',
        './src/index.js'
    ],
    devtool: 'source-map',
    module: {
        rules:[ 
            ...getJSX( 'react-hot', 'babel' ),
            {
                test: /\.css$/,
                use: extractSass.extract({ 
                    use: getStylesheets( 'style', 'css', 'postcss' ),
                    fallbackLoader: 'style-loader'
                })
            }
        ],
    },
    resolve: {
        extensions: ['.jsx', '.js', '.json', 'css']
    },
    output: {
        path: __dirname,
        publicPath: '/',
        filename: 'main.js'
    },
    devServer: {
        historyApiFallback: true,
        contentBase: './webpack_html',
        hot: true
    },
    plugins: [ hotModuleReplacement, extractSass, new webpack.DefinePlugin( constants )]
};
Stephen Isienyi
  • 1,292
  • 3
  • 17
  • 29

1 Answers1

0

All magic is in getStylesheets. Here

 return names.map( 
                    constants.process.env.NODE_ENV ?
                    n => ({ loader: n + '-loader' }) : 
                    n => ({ loader: n + '-loader', options: merge( {}, options, ( specifics[ n ] | {} ))}));

You have

constants = {
            process:{
                env: {
                    NODE_ENV: JSON.stringify( 'development' )
                }
            }
        }

constants.process.env.NODE_ENV will be always true because only empty string will return false. So you will always map

n => ({ loader: n + '-loader' })

and you miss one line

( specifics[ n ] || {} )

Working example.

return names.map(
        constants.process.env.NODE_ENV !== '"development"' ?
                n => ({ loader: n + '-loader' }) :
    n => ({ loader: n + '-loader', options: merge( {}, options, ( specifics[ n ] || {} ))}));

Also there is no postcss-browser-reporter package in demo

Kirill Matrosov
  • 5,564
  • 4
  • 28
  • 39
  • I created the new file named postcss.config in to my root folder either as an empty file or populated the empty exports object as shown above but the same error message continues to be displayed. – Stephen Isienyi May 30 '17 at 19:10
  • @000, it is strange. Can you create blank project on github with this error? – Kirill Matrosov May 31 '17 at 07:28
  • I have created a github repo running only the rc-range-silder react component here https://github.com/snystphn/postcss-config. – Stephen Isienyi Jun 04 '17 at 20:04
  • it seems the error is coming from the css modules of the rc-range-slider component. It is producing the following error: `in ./~/css-loader?{"data":"$env: /"development/";","includePaths":["main","node_modules"],"sourceMap":true}!./~/postcss-loader/lib?{"data":"$env: /"development/";","includePaths":["main","node_modules"],"sourceMap":true}!./~/rc-tipso/lib/Tipso/BaseTipso/base_tipso.css Module build failed: Error: composition is only allowed when selector is single :local class name not in ".tipso-wrapper", ".tipso-wrapper" is weird` – Stephen Isienyi Jun 05 '17 at 21:12
  • I will either try to find a more robust react range slider component or simply implement a new one from scratch – Stephen Isienyi Jun 06 '17 at 13:51