cascornelissen / svg-spritemap-webpack-plugin

SVG spritemap plugin for webpack
MIT License
207 stars 50 forks source link

TypeError: Cannot read property 'content' of undefined #146

Closed andrejs-uibo closed 3 years ago

andrejs-uibo commented 3 years ago

When trying to build assets, I get this error:

node_modules/svg-spritemap-webpack-plugin/lib/index.js:209
                        this.stylesType = this.getStylesType(this.styles.content, stylesOptions.filename);
                                                                         ^
TypeError: Cannot read property 'content' of undefined

Here is a part of webpack config how I use this plugin:

plugins: [
    new SVGSpritemapPlugin("frontend/web/images/features/*.svg", {
      output: {
        filename: "features.svg",
      },
      styles: {
        keepAttributes: true,
        filename: "features.css",
      },
    }),
...

This is on webpack v5.16.0 Plugin v3.8.3

andrejs-uibo commented 3 years ago

This could be related to https://github.com/cascornelissen/svg-spritemap-webpack-plugin/issues/143

Probably need to exit early

if (typeof this.styles === 'undefined') {
    return;
}

before https://github.com/cascornelissen/svg-spritemap-webpack-plugin/blob/842a993f94d3102970051433020f7baee7e75165/lib/index.js#L203

cascornelissen commented 3 years ago

Had a quick look and I've made a similar change in 2b72654 which should also solve this. Would you mind trying to install the plugin from master by using the following command and letting me know if this also solves the problem you're running into?

$ npm install cascornelissen/svg-spritemap-webpack-plugin#master
cascornelissen commented 3 years ago

ping @andrejs-uibo

andrejs-uibo commented 3 years ago

Sorry, have not had the time to check, but it seems like it should solve the issue.

Veron116 commented 3 years ago

There is an error if change the style option error in ./node_modules/svg-spritemap-webpack-plugin/svg4everybody-helper.js

cascornelissen commented 3 years ago

@Veron116, do you have any more information? Are you talking about the latest release on NPM or the master branch?

cascornelissen commented 3 years ago

This change was included in 3.9.0 🚀