webdiscus / html-bundler-webpack-plugin

Alternative to html-webpack-plugin ✅ Renders Eta, EJS, Handlebars, Nunjucks, Pug, Twig templates "out of the box" ✅ Resolves source files of scripts, styles, images in HTML ✅ Uses a template as entry point
ISC License
146 stars 15 forks source link

Favicon plugin causes a crash if no link is included #64

Closed gingershaped closed 11 months ago

gingershaped commented 11 months ago

Current behaviour

If the HTML file does not include a <link rel="icon"> tag and the FaviconBundlerPlugin is enabled, webpack crashes with the following traceback:

  throw new Error('Tap function (tapPromise) did not return promise (returned ' + _promise1 + ')');
        ^

Error: Tap function (tapPromise) did not return promise (returned undefined)
    at _next0 (eval at create (/home/ginger/vyxal.github.io/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:33:9)
    at eval (eval at create (/home/ginger/vyxal.github.io/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:52:1)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Expected behaviour

The plugin should probably throw an error explaining that the file lacks a link tag.

Reproduction Example

Create an HTML file without a <link rel="icon"> tag, enable the FaviconBundlerPlugin, and attempt to bundle it with the HtmlBundlerWebpackPlugin.

Environment

webdiscus commented 11 months ago

Hello @GingerIndustries,

thank you for the issue report. I wil fix it.

webdiscus commented 11 months ago

it is a really special use case <link rel="icon"> or it's an user error? Should be this tag ignored or should an exception occur?

gingershaped commented 11 months ago

it is a really special use case <link rel="icon"> or it's an user error? Should be this tag ignored or should an exception occur?

I'm of the opinion that if the plugin is enabled but the page lacks a favicon it's an error, since why would they have the plugin if they didn't have a favicon to use it with?

webdiscus commented 11 months ago

I'm of the opinion that if the plugin is enabled but the page lacks a favicon it's an error, since why would they have the plugin if they didn't have a favicon to use it with?

yes/no

All use cases such as <link rel="icon"> or <link invalid-href="./favicon.png" rel="icon" /> or the link tag is missing are the same. The plugin doesn't analyse whether any <link> tag exists or not in HTML. The plugin detect and resolve only attributes (href, src, etc) by tags. If any resolvable attribute is missing, then plugin do nothing, HTML stay as is.

Also, I will resolve this case (Favicon file is not found) w/o an exception.

webdiscus commented 11 months ago

But I can display a warning in the console without breaking compilation, for example:

Warning

Favicon file is not found! If the FaviconsBundlerPlugin is used, at last one favicon source file should be defined in the template, e.g.: <link rel="icon" href="path/to/source/favicon.png">

webdiscus commented 11 months ago

@GingerIndustries

the crashing is fixed, in this case will be display a warning. Please check the version 3.4.3.

gingershaped commented 11 months ago

Cool, thanks!