webdiscus / html-bundler-webpack-plugin

Renders Eta, EJS, Handlebars, Nunjucks, Pug, Twig templates "out of the box". Uses HTML template as entry point. Resolves source files of scripts, styles, images in HTML. Supports for Vue.
ISC License
119 stars 12 forks source link

Ignored imports (where an alias is set to `false`) causes error #56

Closed davidmurdoch closed 6 months ago

davidmurdoch commented 7 months ago
ERROR in [entry] [initial]
Cannot read properties of undefined (reading '_bundlerPluginMeta')
TypeError: Cannot read properties of undefined (reading '_bundlerPluginMeta')
    at walk (/home/david/code/metamask-extension2/node_modules/html-bundler-webpack-plugin/src/Plugin/Collection.js:529:67)

https://github.com/webdiscus/html-bundler-webpack-plugin/blob/d278fced2903c68dbebd7de8c76907baea621d8c/src/Plugin/Collection.js#L536

I think the fix might be to check if depModule.resourceResolveData is defined before continuing to walk the dependencies.

p.s., The // TODO: test existing on the same line as the failing code made me smile a little :-)

davidmurdoch commented 7 months ago

Nevermind, adding if (!depModule.resourceResolveData) continue; just causes:

Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
webdiscus commented 7 months ago

Hallo @davidmurdoch,

thanks for the issue report.

Can you please create small repo with the reproducible issue. The TODO was noticed to find a use case where the object can be undefined. You have this use case detected.

webdiscus commented 7 months ago

@davidmurdoch

can you please share your use case. I need it to write the test for this issue.

davidmurdoch commented 7 months ago

I'll try to get something together next week.

davidmurdoch commented 7 months ago

I think my problem was that my webpack file had resolve.extensions = ['.scss', '.ts', '.js']; and my code had both index.js and index.scss in the same directory. The code base is very large and there are lots of moving pieces so it's hard to pinpoint exactly what made it work.

webdiscus commented 7 months ago

the resolve.extensions = ['.scss', '.ts', '.js'] is a wrong config, you should auto resolve only .js, .ts files, but not .scss. If you use resolve.extensions = ['.ts', '.js'] only does the error occur?

davidmurdoch commented 7 months ago

Yeah, sorry I wasn't clear. Removing .scss from resolve.extensions seems to have been the fix for this, as well as some other import issues I was having.

My hunch was that multiple files with the same name, but different extensions (that webpack will resolve), causes some condition that causes a circular walk in this plugin. I suspect a ts file and a js file with the same name will cause the issue as well, but I haven't tried creating a minimal reproduction.

webdiscus commented 6 months ago

@davidmurdoch

the error: Cannot read properties of undefined (reading '_bundlerPluginMeta') is fixed in the ver 3.4.2.

Can be the issue closed? The solution for the circular walk was not using style extensions in the resolve.extensions.

davidmurdoch commented 6 months ago

Can be the issue closed? The solution for the circular walk was not using style extensions in the resolve.extensions.

I don't mind if you close it. But I do think this case should be handled somehow, maybe even just with some documentation about how to do things correctly, like you have for splitChunks (thank you for that! it was so helpful!).

webdiscus commented 6 months ago

@davidmurdoch

I have added in the readme the new section Automatic resolving of file extensions under Problems & Solutions.

You can correct and supplement the text. Any PR is welcome!

davidmurdoch commented 6 months ago

Perfect! You're a really great FOSS maintainer. Thanks once again!

webdiscus commented 6 months ago

Perfect! You're a really great FOSS maintainer. Thanks once again!

If you think this plugin could be useful to other developers, perhaps you can (but not must) promote it (just GitHub link) on your Twitter and/or Reddit ;-)