@@ -230,13 +230,15 @@ class NormalModule extends Module {
230230 return loaderContext ;
231231 }
232232
233- getCurrentLoader ( loaderContext ) {
233+ getCurrentLoader ( loaderContext , index = loaderContext . loaderIndex ) {
234234 if (
235235 this . loaders &&
236236 this . loaders . length &&
237- this . loaders [ loaderContext . loaderIndex ]
237+ index < this . loaders . length &&
238+ index >= 0 &&
239+ this . loaders [ index ]
238240 ) {
239- return this . loaders [ loaderContext . loaderIndex ] ;
241+ return this . loaders [ index ] ;
240242 }
241243 return null ;
242244 }
@@ -296,9 +298,11 @@ class NormalModule extends Module {
296298 if ( err ) {
297299 const currentLoader = this . getCurrentLoader ( loaderContext ) ;
298300 const error = new ModuleBuildError ( this , err , {
299- from : compilation . runtimeTemplate . requestShortener . shorten (
300- currentLoader . loader
301- )
301+ from :
302+ currentLoader &&
303+ compilation . runtimeTemplate . requestShortener . shorten (
304+ currentLoader . loader
305+ )
302306 } ) ;
303307 return callback ( error ) ;
304308 }
@@ -309,10 +313,17 @@ class NormalModule extends Module {
309313 const extraInfo = result . result . length >= 2 ? result . result [ 2 ] : null ;
310314
311315 if ( ! Buffer . isBuffer ( source ) && typeof source !== "string" ) {
312- const error = new ModuleBuildError (
313- this ,
314- new Error ( "Final loader didn't return a Buffer or String" )
316+ const currentLoader = this . getCurrentLoader ( loaderContext , 0 ) ;
317+ const err = new Error (
318+ `Final loader (${
319+ currentLoader
320+ ? compilation . runtimeTemplate . requestShortener . shorten (
321+ currentLoader . loader
322+ )
323+ : "unknown"
324+ } ) didn't return a Buffer or String`
315325 ) ;
326+ const error = new ModuleBuildError ( this , err ) ;
316327 return callback ( error ) ;
317328 }
318329
0 commit comments