cascornelissen / svg-spritemap-webpack-plugin

SVG spritemap plugin for webpack
MIT License
210 stars 51 forks source link

Broken build 3.5.8 #118

Closed maxmadknight closed 4 years ago

maxmadknight commented 4 years ago

On build 3.5.8 getting next error, on 3.5.7 all is OK

SVGSpritemapPlugin(node:3562603) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined
    at /home/mihail-opanasenko/www/project/node_modules/svg-spritemap-webpack-plugin/lib/index.js:291:77
    at Array.forEach (<anonymous>)
    at /home/mihail-opanasenko/www/project/node_modules/svg-spritemap-webpack-plugin/lib/index.js:290:32
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/mihail-opanasenko/www/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
    at AsyncSeriesHook.lazyCompileHook (/home/mihail-opanasenko/www/project/node_modules/tapable/lib/Hook.js:154:20)
    at Compiler.emitAssets (/home/mihail-opanasenko/www/project/node_modules/webpack/lib/Compiler.js:367:19)
    at onCompiled (/home/mihail-opanasenko/www/project/node_modules/webpack/lib/Compiler.js:235:9)
    at /home/mihail-opanasenko/www/project/node_modules/webpack/lib/Compiler.js:556:14
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/mihail-opanasenko/www/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
    at AsyncSeriesHook.lazyCompileHook (/home/mihail-opanasenko/www/project/node_modules/tapable/lib/Hook.js:154:20)
    at /home/mihail-opanasenko/www/project/node_modules/webpack/lib/Compiler.js:553:30
    at AsyncSeriesHook.eval [as callAsync] (eval at create (/home/mihail-opanasenko/www/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at AsyncSeriesHook.lazyCompileHook (/home/mihail-opanasenko/www/project/node_modules/tapable/lib/Hook.js:154:20)
    at /home/mihail-opanasenko/www/project/node_modules/webpack/lib/Compilation.js:1323:35
    at eval (eval at create (/home/mihail-opanasenko/www/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:17:1)
    at /home/mihail-opanasenko/www/project/node_modules/svg-spritemap-webpack-plugin/lib/index.js:254:32
    at _next0 (eval at create (/home/mihail-opanasenko/www/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:13:1)
    at eval (eval at create (/home/mihail-opanasenko/www/project/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:28:1)
    at /home/mihail-opanasenko/www/project/node_modules/svg-spritemap-webpack-plugin/lib/index.js:245:32
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:3562603) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 95)
cascornelissen commented 4 years ago

Hmm, strange, could you share your Node.js and Webpack versions?

maxmadknight commented 4 years ago

node v12.14.0 npm 6.14.7

But this issue was discovered on product server with other versions. Can tell exactly

cascornelissen commented 4 years ago

Are you able to reproduce it on your local system with these versions? Also still missing the Webpack version 😅

ivankristianto commented 4 years ago

I share the same issue:

node: v12.16.2
webpack: v4.44.1
webpack-cli: v3.3.12

Downgrading to v3.5.7 fix the issue.

cascornelissen commented 4 years ago

Interesting, I can’t seem to reproduce it but I’ll push a potential fix for this later today if multiple people are experiencing this.

ivankristianto commented 4 years ago

@cascornelissen thanks for your quick reply. Perhaps my webpack configuration might help you to figure out what happen:

new SVGSpritemapPlugin(
        [
          './src/images/svg-sprite/**/*.svg',
        ],
        {
          output: {
            filename: 'polaris-sprite.svg',
            svg4everybody: false,
            svgo: {
              plugins: [
                { removeDesc: true },
                { removeAttrs: { attrs: 'fill|class|style' } },
                { removeStyleElement: true },
                { removeRasterImages: true },
                { sortAttr: true },
              ],
            },
          },
          sprite: {
            prefix: 'polaris__',
          },
        },
      ),
cascornelissen commented 4 years ago

Took a bit longer than I hoped but the fix in 672bb2b6 should resolve this. Could any of you try this out?

npm install --no-save cascornelissen/svg-spritemap-webpack-plugin#118
cascornelissen commented 4 years ago

Pinging @maxgram and @ivankristianto (or anyone else who can reproduce the original issue) to make sure the fix gets verified before making a release.

ivankristianto commented 4 years ago

@cascornelissen from my quick test, it still doesn't work. I think this is more on compatible issue with my setup. Let me hunt it down this weekend and post anything I found here.

cascornelissen commented 4 years ago

Thanks, I don't think there's any way for the same error to pop up when installing from the 118 branch so please include the actual error/stacktrace if you're running into anything ✌🏼

ivankristianto commented 4 years ago

@cascornelissen I'm very curious about this issue and spent a bit of time to hunt it down. And better, i provide the proof of concept what causing the issue. Here is the repo: https://github.com/ivankristianto/svg-spritemap-webpack-plugin-demo

And if you enable this line: https://github.com/ivankristianto/svg-spritemap-webpack-plugin-demo/blob/master/src/client.js#L5

And do yarn && yarn build, it will throw this error:

95% [0] emitting SVGSpritemapPlugin(node:10529) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of null

my environment:

node: v12.16.2
webpack: v4.44.1
webpack-cli: v3.3.12

And if you try with the version 3.5.7, it can compile successfully.

If there is anything I can help you more, please let me know.

And last but not least, thank you so much for your help and build / maintain this plugin.

cascornelissen commented 4 years ago

That error helps a lot, it's slightly different than the initial issue (Cannot read property 'startsWith' of undefined vs Cannot read property 'startsWith' of null). Apparently both of you have chunks without a name for some reason and apparently chunk.name can be both undefined and null 🤷🏼‍♂️

Could you try installing it from the 118 branch once more? It should now handle both edge cases.

ivankristianto commented 4 years ago

@cascornelissen yes it's working for my case! Thank you so much.

cascornelissen commented 4 years ago

@ivankristianto, the fix for this issue has been released in version 3.5.9 🚀 I'm expecting this to also solve the original issue, thanks for helping me debug it!

rtatarinov4xxi commented 4 years ago

Thanks. It's very useful improve for me right now :smile: