简体   繁体   中英

Error when trying to work with css-loader

While developing with Reactjs, I have problem with css-loader. Basically, this is my webpack.config :

{
test: /\.css$/,
exclude: /node_modules/,
loader: 'style-loader!css-loader?localIdentName=[name]__[local]__[hash:base64:5]&modules&importLoaders=1&sourceMap!postcss-loader',
}, {
test: /\.css$/,
include: /node_modules/,
loaders: ['style-loader', 'css-loader'],
},

And this is how I implement the css :

import styles from './Home.css';
.
.
.
<FormControl type="text" className={styles['input-search']}/>

This is my Home.css

.input-search{
width: 500px;
}

I'm using Hasnode's mern-starter

But there are no css is loaded. What should I do ?

在此处输入图片说明

在此处输入图片说明

Just change it to this and see if it works:

{
    test: /\.css$/,
    loader: 'style-loader!css-loader'
}

If that works, then add your exclude: /node_modules/ and finally, if that works, then add all your crazy ?localIdentName=[name]__[local]__[hash:base64:5]&modules&importLoaders=1&sourceMap additions.

Also consider adding a resolve section to your config:

resolve: {
    modules: [
      path.join(__dirname, '../src/components'),
      'node_modules'
    ],
    extensions: ['.js', '.jsx', '.css']
  },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM