@@ -26,11 +26,23 @@ function getViewerData(bundleStats, bundleDir, opts) {
2626
2727 const isAssetIncluded = createAssetsFilter ( excludeAssets ) ;
2828
29- // Sometimes all the information is located in `children` array (e.g. problem in #10)
30- if (
31- ( bundleStats . assets == null || bundleStats . assets . length === 0 )
32- && bundleStats . children && bundleStats . children . length > 0
33- ) {
29+ // Handle minimal stats format that only has assetsByChunkName but no assets array
30+ if ( ( bundleStats . assets == null || bundleStats . assets . length === 0 ) && bundleStats . assetsByChunkName ) {
31+ // Convert assetsByChunkName to assets array for minimal stats
32+ bundleStats . assets = [ ] ;
33+ Object . entries ( bundleStats . assetsByChunkName ) . forEach ( ( [ chunkName , assetNames ] ) => {
34+ assetNames . forEach ( assetName => {
35+ bundleStats . assets . push ( {
36+ name : assetName ,
37+ chunks : [ chunkName ] ,
38+ size : 0 // Default size for minimal stats
39+ } ) ;
40+ } ) ;
41+ } ) ;
42+ }
43+
44+ // Sometimes all the information is located in `children` array (e.g. problem in #10)
45+ if ( ( bundleStats . assets == null || bundleStats . assets . length === 0 ) && bundleStats . children && bundleStats . children . length > 0 ) {
3446 const { children} = bundleStats ;
3547 bundleStats = bundleStats . children [ 0 ] ;
3648 // Sometimes if there are additional child chunks produced add them as child assets,
@@ -189,13 +201,21 @@ function getChildAssetBundles(bundleStats, assetName) {
189201}
190202
191203function getBundleModules ( bundleStats ) {
204+ // Handle case where bundleStats is undefined or has no modules/chunks
205+ if ( ! bundleStats ) {
206+ return [ ] ;
207+ }
208+
192209 const seenIds = new Set ( ) ;
193-
194- return flatten (
195- ( ( bundleStats . chunks ?. map ( chunk => chunk . modules ) ) || [ ] )
196- . concat ( bundleStats . modules )
197- . filter ( Boolean )
198- ) . filter ( mod => {
210+
211+ // Safely handle chunks and modules that might be undefined
212+ const chunksModules = bundleStats . chunks ?
213+ bundleStats . chunks . map ( chunk => chunk . modules || [ ] ) :
214+ [ ] ;
215+
216+ const statsModules = bundleStats . modules || [ ] ;
217+
218+ return flatten ( chunksModules . concat ( statsModules ) . filter ( Boolean ) ) . filter ( mod => {
199219 // Filtering out Webpack's runtime modules as they don't have ids and can't be parsed (introduced in Webpack 5)
200220 if ( isRuntimeModule ( mod ) ) {
201221 return false ;
0 commit comments