Error: Cannot resolve module 'style-loader'

前端 未结 8 2036
情书的邮戳
情书的邮戳 2020-12-24 04:33

I\'m using style-loader with webpack and react framework. When I run webpack in terminal i\'m getting Module not found: Error: Cannot resolve module \'style-loader\'

8条回答
  •  暖寄归人
    2020-12-24 05:03

    Please run this script:

     npm install style-loader css-loader --save
    

    Set your module as below:

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

    It's basically reading as for loaders - test jsx using babel-loader and the next test is a css file using style-loader and css-loader, which will recognize the modules. Also, you should exit out of npm start, and run "npm install" and run "npm start". Hopefully, this should take care of the issue.

提交回复
热议问题