Skip to content

Module build failed: Error: resolve-url-loader: CSS error #107

Closed
@netdjw

Description

@netdjw

Hi,

I have a strange malfunction with resolve-url-loader. I have this webpack.config.js:

const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');

module.exports = {
  entry: ['./src/main.js', './src/main.scss'],
  output: {
    path: path.resolve(__dirname, './dist'),
    filename: 'index.js'
  },
  devtool: "source-map",
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          use: [
            { loader: 'css-loader', options: { minimize: true, sourceMap: true } },
            { loader: 'resolve-url-loader', options: { sourceMap: true } },
            { loader: 'sass-loader', options: { sourceMap: true } },
            
          ]
        })
      },

      {
        test: /\.(jpg|png|gif|ico|svg)$/,
        use: [{
          loader: 'file-loader',
          options: {name: '[name].[ext]', publicPath: 'img/', outputPath: 'img/'}
        }]
      },

      {
        test: /\.html$/,
        use: [
          {
            loader: 'html-loader',
            options: {
              interpolate: true
            }
          }
        ]
      }
    ]
  },
  plugins: [

    new ExtractTextPlugin({ // define where to save the file
      filename: 'style.css',
      allChunks: true,
    }),

    new HtmlWebpackPlugin({
      template: './src/main.html',
      filename: 'index.html'
    }),

    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery",
      "window.jQuery": "jquery"
    })

  ],
};

this is the package.json file:

{
  "name": "my-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build:watch": "webpack --watch"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "css-loader": "^1.0.0",
    "extract-text-webpack-plugin": "^3.0.2",
    "file-loader": "^2.0.0",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "node-sass": "^4.9.3",
    "resolve-url-loader": "^3.0.0",
    "sass-loader": "^7.1.0",
    "webpack": "^3.9.1"
  },
  "dependencies": {
    "bootstrap": "^4.1.3",
    "jquery": "^3.3.1",
    "owl.carousel": "^2.3.4",
    "popper.js": "^1.14.4"
  }
}

In the SCSS file I have this line what is the reason of the problem:

background-image: url('img/hero-slider-arrow.png');

I tried to change this line to this one:

background-image: url('data:image/png;base64,iVBORw0KGgoAAAA...==');

And in both case I got this error message:

ERROR in ./node_modules/css-loader??ref--0-1!./node_modules/resolve-url-loader??ref--0-2!./node_modules/sass-loader/lib/loader.js??ref--0-3!./src/main.scss
    Module build failed: Error: resolve-url-loader: CSS error
      source-map information is not available at url() declaration
      at file://d:\LARAVEL\Code\my-project\src\main.scss:7252:5
        at encodeError (d:\LARAVEL\Code\my-project\node_modules\resolve-url-loader\index.js:218:12)
        at onFailure (d:\LARAVEL\Code\my-project\node_modules\resolve-url-loader\index.js:175:14)
        at process._tickCallback (internal/process/next_tick.js:68:7)

Doublechecked the image file is on that path what is given. But if I use data:image/png solution... same error message. I don't understand what is the problem.

The other images working fine with similar url('img/filename.png') format.

Any idea?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions