0
votes

I'm learning to build my react project using Webpack. I already have configuration a webpack.config.js to load CSS file.

webpack.config.js:

module.exports = {

  ...

  module: {
    rules: [

      {
        test: /\.css$/,
        exclude: /(node_modules)/,
        use: [
          { loader: 'style-loader' },
          { loader: 'css-loader' },
        ],
      },
      {
        test: /\.scss$/,
        exclude: /(node_modules)/,
        use: [
          { loader: 'style-loader' },
          { loader: 'css-loader' },
          { loader: 'sass-loader' },
        ],
      },

     ...

    ],
  },
  
  ...

}

npm run build

This problem appeared.

Module parse failed: Unexpected token (6:3) You may need an
appropriate loader to handle this file type, currently no loaders are
configured to process this file. See
https://webpack.js.org/concepts#loaders |  * Copyright 2011-2020
Twitter, Inc. |  * Licensed under MIT
(https://github.com/twbs/bootstrap/blob/main/LICENSE)
>  */:root{--blue:#007bff;--indigo:#6610f2;--purple:#6f42c1;--pink:#e83e8c;--red:#dc3545;
.....  ```

I don't understand what should to do. Thank you.

1

1 Answers

1
votes

Not sure why you exclude node_modules why you're still importing css from there which means just remove exclude: /(node_modules)/ then would work:

{
  test: /\.css$/,
  // exclude: /(node_modules)/, // Remove this 
  use: [
    { loader: 'style-loader' },
    { loader: 'css-loader' },
  ],
},