#9309·webpack

Rule with issuer is not applied when importing via require.context

Author: andrey-sklCreated Jun 20, 2019Updated Sep 8, 2026
Labelswebpack-5

Bug report

What is the current behavior? Loaders are not applied for files, imported via require.context, if rule has "issuer" option.

If the current behavior is a bug, please provide the steps to reproduce. See reproduction https://github.com/huston007/webpack-issuer-repro

In short: In webpack.config:

rules: [
      {
        test: /\.svg/,
        issuer: /\.js/, // Remove this line and everything works
        loader: 'url-loader'
      }
    ]

a.js:

function importAll (r) {
  r.keys().forEach(r);
}

importAll(require.context('.', false, /\.svg$/));

Build error:

WARNING in ./circle.svg 1:0
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><circle cx="8" cy="8" r="8"/></svg>
 @ . sync nonrecursive \.svg$ ./circle.svg
 @ ./a.js

Note that it is doesn't matter what is inside "issuer" property. It also breaks if using wildcarded require like require('./'+fileName+'.svg')

What is the expected behavior? Loaders are applied in-spite of a way how file is imported: via direct require or via context.

Known workaround It is possible to workaround by inlining loader syntax like: require.context('!file-loader!./', true, /\.svg$/)

Other relevant information: webpack version: 4.35.0 Node.js version: 10.15.0 Operating System: macOS

Maybe related to #6915