Closed xc2 closed 6 months ago
Try to enable module
in SWC js minifier plugin.
I've simplified the reproduction.
This problem occurs when importing a "module"
package whose main file contains new URL("./", import.meta.url)
.
Both rspack and webpack will create an asset file xxx.js
for the main file itself because of the statement new URL("./", import.meta.url)
as documented: https://webpack.js.org/guides/asset-modules/#url-assets
Consider the foo
example, the package foo
has these two traits:
new URL("./", import.meta.url)
in foo/index.js
"module"
packageWhen importing foo
, both rspack and webpack will
foo/index.js
into the main asset filexxxx.js
whose content is same as foo/index.js
When minimizing the xxxx.js
file, depending on the value of package "type"
package type of foo |
minimize | rspack | webpack |
---|---|---|---|
"module" |
ON | β[1] | β |
"commonjs" |
ON | β[2] | β[2] |
"module" |
OFF | β | β |
"commonjs" |
OFF | β[2] | β[2] |
After dig into it, I just found
module: undefined
while rspack minifies it with module: false
System Info
Details
Code
Configuration
Got
Expected
There's
type:"module"
inbinaryen/package.json
so it should be considered as module codeMore
This only happens when minimize is on
Reproduce link
https://github.com/xc2/rspack-repro-binaryen
Reproduce Steps