3

Here's my webpack.config.js. I can't make it work. Besides that code, I provide 'import '../style.css' to my root component. I split the code to 2 bundles and want to get the third, this time with the css. However, it doesn't work.

const webpack = require('webpack');
const path =  require('path');

module.exports = {
  entry: {
  app: ['./src/App.jsx'],
  vendor: ['react','react-dom','whatwg-fetch','babel-polyfill','react- 
         router','react-router-bootstrap','react-bootstrap'],
 },

  output: {
  path:path.resolve(__dirname,'static'),
  filename: 'app.bundle.js',  
},
module: {
 loaders: [  
{
  test: /\.css$/,
 loader: 'style-loader'
},   
{
  test: /\.css$/,
 loader: 'css-loader'
 },      
    {
      test: /\.jsx$/,
      loader: 'babel-loader',
      query: {
         presets: ['react','es2015']
    }, 
  },
 ],
   resolve: {
      extensions:['.js','.jsx','.css'],
   },
 },
plugins: [
new webpack.optimize.CommonsChunkPlugin('vendor','vendor.bundle.js'), 
  ],
}

Module not found: Error: Cannot resolve module 'css-loader'

3 Answers 3

4

Make sure you have the css-loader and style-loader modules installed

npm install style-loader css-loader --save-dev

You can also chain your loaders together so that you only have one rule block for your css

test: /\.css$/,
use: [
    {
        loader: 'style-loader'
    },
    {
        loader: 'css-loader'
    }
]
Sign up to request clarification or add additional context in comments.

1 Comment

Well, I actually kinda forgot to install one of them. THANK YOU! It worked!
0

I have CRA and today it stopped starting because of this error

Installing css-loader directly worked for me

npm install css-loader --save-dev

Comments

-1

Luke Flournoy provided a perfect answer to this question. Make sure you have the css-loader and style-loader modules installed

npm install style-loader css-loader --save-dev

You can also chain your loaders together so that you only have one rule block for your css

test: /\.css$/,
use: [
    {
        loader: 'style-loader'
    },
    {
        loader: 'css-loader'
    }
]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.