-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Invalid URL error thrown when using html-loader #3353
[Bug]: Invalid URL error thrown when using html-loader #3353
Comments
Rsbuild does not support html-loader yet, we will try to support it. |
@chenjiahan Hai, I may know why, |
html-webpack-plugin 或者 html-webpack-plugin,在执行childCompiler的时候,调用 createChildCompiler 会复制所有的parse 配置,同时会设置 module.parse.javascript.url 为 ‘relative’, url 为 ‘relative’决定了资源打包成独立资源被引入 boundle的时候是否通过 new URL,new URL中的资源是相对路径,new URL(input, base)中 base不是绝对路径会在 vmscript.runInContext中报错,这是根本原因。 对于webpack,在config.js中只会生成 parse.javascript的配置,在实际遇到图片的asset时,非parse.javascript配置的javasct资源会使用parse.javascript配置,所以在执行 childCompiler 时,只有parse.javascript,且 parse.javascript.url 被设置为’relative’,所以现象是对的。 对于rspack,在default.js中会初始化parse[‘javascript/esm | auto’]等的配置,所以执行childCompiler的时候只设置了 parse.javascript.url的值为’relative’,parse[‘javascript/auto’] 是之前初始化过的配置,parse[‘javascript/auto’].url 还是 true,所以在编译后 对于图片资源 引入还是会是 new URL, parse部分理解还是不大理解,你看看是不是这个原因。 |
Thank you for the information! This should be the root cause of the problem. I will set @ahabhgk Do you think Rspack should align the default behavior of |
It's a bug, we should fix it |
Version
System: OS: macOS 14.6.1 CPU: (8) arm64 Apple M1 Memory: 121.88 MB / 8.00 GB Shell: 5.9 - /bin/zsh Browsers: Chrome: 128.0.6613.113 Safari: 17.6 npmPackages: @rsbuild/core: 1.0.1-beta.15 => 1.0.1-beta.15
Details
Problem
When migrating a project from Webpack to RsBuild, I've encountered an "Invalid URL" error during the build/development process. This issue specifically occurs when using the
html-loader
in conjunction withrspack.htmlRspackPlugin
orhtml-webpack-plugin
. It seems the parsing of src attributes within HTML tags is triggering this error.Expected Behavior
The build process should complete successfully without any errors, correctly processing the HTML files and resolving the asset paths.
Actual Behavior
An "Invalid URL" error is thrown during the build, indicating an issue with parsing the src attribute in HTML tags.
Reproduce link
https://github.com/BrinsilElias/rsbuild-html-loader
Reproduce Steps
Steps to Reproduce
rspack.htmlRspackPlugin
orhtml-webpack-plugin
.html-loader
in the configuration to process HTML files. Within an HTML file, use tags like<img>
withsrc
attributes pointing to assets.pnpm run build
orpnpm run dev
The text was updated successfully, but these errors were encountered: