levp / wrapper-webpack-plugin

A webpack plugin that wraps output files (chunks) with custom text or code.
91 stars 37 forks source link

TypeError: Cannot read property 'sources' of undefined #19

Closed brucewar closed 2 years ago

brucewar commented 2 years ago

This error occurs recently, but 2.1.0 has no problem

antipenko commented 2 years ago

exactly the same problem and everything is also ok if you install version 2.1.0

levp commented 2 years ago

@brucewar @antipenko

I can't recreate this issue with the following packages:

Can you give me a minimal example of a configuration that recreates this error?

brucewar commented 2 years ago
const WrapperPlugin = require('wrapper-webpack-plugin');

{
   plugins: [
     new Wrapper({
       header: '(function() {\n',
       footer: '\n})();'
     })
   ]
}
levp commented 2 years ago

Ah yes, I managed to reproduce this. It seems like the way source concatenation is done in webpack 5 doesn't work in webpack 4, and the commit that fixed compatibility with webpack 5 broke backwards compatibility with webpack 4.

79f498302b2adbfc77e566a0a860ef046352bce3 fixes this by trying to use whichever one is available, and from my testing works with both webpack 4 and 5.

Published new version 2.2.2 to npm which includes this fix.

antipenko commented 2 years ago

@levp Sorry i miss your previus comment. Thanks you for fast fix!🙏