Categories
JavaScript Answers

How to fix Error: Cannot resolve module ‘style-loader’ with JavaScript?

Spread the love

Sometimes, we want to fix Error: Cannot resolve module ‘style-loader’ with JavaScript.

In this article, we’ll look at how to fix Error: Cannot resolve module ‘style-loader’ with JavaScript.

How to fix Error: Cannot resolve module ‘style-loader’ with JavaScript?

To fix Error: Cannot resolve module ‘style-loader’ with JavaScript, we install style-loader and add it to the Webpack config.

To install it, we run

npm install style-loader css-loader --save

to install the style-loader and css-loader packages.

Then in our Webpack config file, we write

module.exports = {
  //...
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        loader: "babel-loader",
        include: path.join(_dirname, "app"),
      },
      {
        test: /\.css$/,
        loader: "style-loader!css-loader",
      },
    ],
    resolve: {
      extensions: ["", ".js", ".jsx", ".css"],
    },
  },
};

to use the css-loader for importing CSS fiiles.

Conclusion

To fix Error: Cannot resolve module ‘style-loader’ with JavaScript, we install style-loader and add it to the Webpack config.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *