A
A
Anatoly2017-06-21 23:44:03
Sass
Anatoly, 2017-06-21 23:44:03

Why doesn't webpack compile Sass files?

Good afternoon!
Can you please tell me why when compiling scss files that contain backgroung:('../src), webpack gives an error:

ERROR in ./~/css-loader!./~/sass-loader/lib/loader.js!./~/resolve-url-loader!./src/components_test/menu/menu.scss
Module not found: Error: Can't resolve '../src/img/header/header_bg.jpg' in 'D:\STUDY\Development site\My work\Portfolio\src\components_test\menu'
 @ ./~/css-loader!./~/sass-loader/lib/loader.js!./~/resolve-url-loader!./src/components_test/menu/menu.scss 6:104-146
 @ ./src/components_test/menu/menu.scss
 @ ./src/components_test/menu/menu.js

Config and json below:
/------------------------------ config-------------/
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('Extract-text-webpack-plugin');

const PATHS = {
  source: path.join(__dirname, './src/'),
  build: path.join(__dirname, 'public')
};

module.exports = {
  entry: {
     'menu': PATHS.source + 'components_test/menu/menu.js',

  },
  output: {
    path: PATHS.build,
    filename: 'js/[name].js'
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: 'about.html',
      chunks: ['about', 'unit'],
      template: PATHS.source + 'html/pages/about/about.pug'
    }),
    new HtmlWebpackPlugin({
      filename: 'blog.html',
      chunks: ['blog', 'unit'],
      template: PATHS.source + 'html/pages/blog/blog.pug'
    }),
    new HtmlWebpackPlugin({
      filename: 'login.html',
      chunks: ['login', 'unit'],
      template: PATHS.source + 'html/pages/login/login.pug'
    }),
    new HtmlWebpackPlugin({
      filename: 'welcome.html',
      chunks: ['welcome', 'unit'],
      template: PATHS.source + 'html/pages/welcome/welcome.pug'
    }),
    new HtmlWebpackPlugin({
      filename: 'works.html',
      chunks: ['works', 'unit'],
      template: PATHS.source + 'html/pages/works/works.pug'
    }),
    new ExtractTextPlugin('./css/[name].css'),
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery'
    }),
      new webpack.optimize.CommonsChunkPlugin({   
      name: 'unit',
    })
  ],
  module: {
    loaders: [
     
      {
        test   : /\.scss$/,
        loaders: ['style-loader', 'css-loader',  'sass-loader?sourceMap','resolve-url-loader']
      },

      {
        test: /\.(jpg|png|gif)$/,
        include: /img/,
        loader: 'url-loader'
      },
      { test: /\.(woff|woff2|eot|ttf|svg)$/, loader: 'url-loader' },
    ],


    rules: [
      {
        test: /\.css$/,
        // include: paths,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: 'css-loader',
        }),
      },
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          publicPath: './',
          fallback: 'style-loader',
          use: ['css-loader', 'sass-loader', 'resolve-url-loader'],
        }),
      },

      {
        test: /\.(jpg|png|svg)$/,
        loader: 'file-loader',
        options: {
          name: 'images/[name].[ext]'
        },
      },
      {
        test: /\.pug$/,
        loader: 'pug-loader',
        options: {
          pretty: true
        }
      },
    ],

  },
  devServer: {
    stats: 'errors-only',
    port: 9000
  },
};

/---------------------- json-------------/
{
  "name": "Portfolio",
  "version": "1.0.0",
  "main": "portfolio.js",
  "license": "MIT",
  "dependencies": {
    "jquery": "^3.2.1",
    "normalize.css": "^7.0.0"
  },
  "scripts": {
    "start": "webpack-dev-server --env development",
    "build": "webpack --env production",
    "serv": "static build"
  },
  "devDependencies": {
    "app-root-path": "^2.0.1",
    "components-font-awesome": "^4.7.0",
    "css-loader": "^0.28.4",
    "extract-text-webpack-plugin": "^2.1.2",
    "file-loader": "^0.11.2",
    "html-webpack-plugin": "^2.28.0",
    "imports-loader": "^0.7.1",
    "node-sass": "^4.5.3",
    "node-static": "^0.7.9",
    "pug": "^2.0.0-rc.2",
    "pug-loader": "^2.3.0",
    "resolve-url-loader": "^2.0.3",
    "sass-loader": "^6.0.6",
    "scss-loader": "^0.0.1",
    "style-loader": "^0.18.2",
    "url-loader": "^0.5.9",
    "webpack": "2.3.3",
    "webpack-dev-server": "^2.5.0"
  }
}

In menu.js I wrote: import './menu.scss';
Thank you in advance !

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Medvedev, 2017-06-22
@lifestar

1. Running with --debug --display-error-details often helps to see the problem
2. Swap loaders: sass-loader?sourceMap and resolve-url-loader

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question