discuss for remove unused argument in runtime function template in webpack5
See original GitHub issueI’m not sure if this is a bug or expected feature(not compatibility for the wrong module library),so I marked it as discuss.
good case
when we not use module spec keyword like module,require ,import,export etc in js file
// a.js
console.log(1)
in webpack4 ,we will get output like
function(module, exports){
console.log(1)
}
but webpack5 ( maybe this commit ) ,we will get output like
function(/* argument is omit for unused */){
console.log(1)
}
I think this is a useful optimization in most cases。
bad case
However. suppose you have a library whick name “A”
// my simple lib A
eval("if(typeof module === 'object') module.exports='A'")
in webpack4 we will get string "A" with import A from "A"
function(module, exports){
eval("if(typeof module === 'object') module.exports='A'")
}
but in webpack5 we get an empty object {}. because arcon ast can not detect the correlation of the module variable.so that the first module argument will be remove due to unused
function(/* argument is omit for unused */){
eval("if(typeof module === 'object') module.exports='A'")
}
real case
we use a lib which name watermark-dom(it has a star close to 1k github npm) in webpack5
Below is the minimal reproduce link https://github.com/VisonM/webpack-reproduce-demo
Summarize
I have to say the npm package of watermark-dom is terrible, but do we still need to be compatible with such libs?if we should keep unused argument when code exist some keyword like eval,new Function etc
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
@alexander-akait @vankop Thanks for your patience!🌈 just closed this issue.
I think
noParseis enough for such weird libraries.I also found docs about runtime optimization in release blog, but I think it’s a little obscure for developers, I may send a docs pr to optimized, make it more understandable, but it’s a bit difficult for me, I haven’t done anything like that, but I’ll try my best.
These changes happen because webpack v5 is more stricky
Workaround:
But I think it’s really weird and I don’t think this code should be used in libraries
And yes - welcome to update docs