question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use webpack@2 RuleSet to match rules

See original GitHub issue

Do you want to request a feature, report a bug or ask a question? Bug

What is the current behavior? Loader throws this error:

C:\dev\svg-sprite-loader-bug-repro\node_modules\svg-sprite-loader\lib\utils\get-loader-options.js:25
    options = multiRule.map(normalizeRule).find(r => loaderPath.includes(r.loader)).options;
                                                                                   ^

TypeError: Cannot read property 'options' of undefined
    at getLoaderOptions (C:\dev\svg-sprite-loader-bug-repro\node_modules\svg-sprite-loader\lib\utils\get-loader-options.j
s:25:84)

What is the expected behavior? No error and project to be built

Steps to reproduce:

This bug occurrs ONLY in the following setup:

  • loader rule is inside of use array
  • use rules.oneOf configuration
  • extract option set to true
  • plainSprite option set to true

Please tell us about your environment:

  • Node.js version: 8.5.0
  • webpack version: 3.8.1
  • svg-sprite-loader version: 3.4.0
  • OS type & version: Windows 10

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sqalcommented, Oct 15, 2018

@kisenka I have the same issue as @raduflp after updating to the 4.1.1. You can use his reproduction to investigate the issue.

Logs:

TypeError: Cannot read property 'options' of undefined
    at module.exports (C:\dev\Github\svg-sprite-loader-bug-repro\node_modules\svg-sprite-loader\lib\utils\get-matched-rule.js:12:15)
    at SVGSpritePlugin.apply (C:\dev\Github\svg-sprite-loader-bug-repro\node_modules\svg-sprite-loader\lib\plugin.js:65:18)
    at webpack (C:\dev\Github\svg-sprite-loader-bug-repro\node_modules\webpack\lib\webpack.js:47:13)
    at processOptions (C:\dev\Github\svg-sprite-loader-bug-repro\node_modules\webpack-cli\bin\cli.js:441:16)
    at yargs.parse (C:\dev\Github\svg-sprite-loader-bug-repro\node_modules\webpack-cli\bin\cli.js:536:3)
    at Object.parse (C:\dev\Github\svg-sprite-loader-bug-repro\node_modules\yargs\yargs.js:563:18)
    at C:\dev\Github\svg-sprite-loader-bug-repro\node_modules\webpack-cli\bin\cli.js:219:8
    at Object.<anonymous> (C:\dev\Github\svg-sprite-loader-bug-repro\node_modules\webpack-cli\bin\cli.js:538:3)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (C:\dev\Github\svg-sprite-loader-bug-repro\node_modules\webpack\bin\webpack.js:155:2)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:279:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:752:3)

btw. I noticed that unit test that supposed to test this setup was deleted in this commit, maybe it should be reinstated?

https://github.com/kisenka/svg-sprite-loader/commit/9418920038e72db1b88ab0bd24552420a8a3894d#diff-94ddd23a53d918ba243886e5b60a78afL440

1reaction
raduflpcommented, Sep 21, 2018

this issue has resurfaced in my case after upgrading from 3.9.x to 4.1.1 my config looks something along the lines

...
module: {
  rules: [
    {
      oneOf: [
        ...
        {
           test: /\.svg$/,
           include: [/icons/],
           loader: "svg-sprite-loader",
           options: { extract: true }
         },
         ...
      ]
    }
  ]
}

looking at the recent webpack docs examples { oneOf: [ /* rules */ ] }, should be a valid rule.

@kisenka any thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

GreenGremlin/webpack-ruleset: A class for working with ...
WebpackRuleset is a slimmed down version of webpack/lib/RuleSet for matching, modifying, and inserting rules in webpack config. Webpack's ...
Read more >
Module | webpack - JS.ORG
An array of Rules which are matched to requests when modules are created. These rules can modify how the module is created. They...
Read more >
i have this probleme in webpack.config.js
Webpack has been initialised using a configuration object that does not match the API schema. - configuration.module.rules[0] has an unknown ...
Read more >
Bud Vue - loader not applying to files outside of the @src
See https://webpack.js.org/concepts#loaders │ > <template> │ | <h1>Gday! ... oneOf: an array of Rules from which only the first matching Rule is used...
Read more >
Rulesets
Route events and take action based on predefined event rules. ... This will match events where the severity field does not equal critical...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found