@@ -146,6 +146,7 @@ function successfulTypeScriptInstance(
146146 }
147147 }
148148
149+ const module = loader . _module ;
149150 const basePath = loaderOptions . context || path . dirname ( configFilePath || '' ) ;
150151 const configParseResult = getConfigParseResult (
151152 compiler ,
@@ -165,7 +166,15 @@ function successfulTypeScriptInstance(
165166 loader . context
166167 ) ;
167168
168- loader . _module . errors . push ( ...errors ) ;
169+ /**
170+ * Since webpack 5, the `errors` property is deprecated,
171+ * so we can check if some methods for reporting errors exist.
172+ */
173+ if ( module . addError ) {
174+ errors . forEach ( error => module . addError ( error ) ) ;
175+ } else {
176+ module . errors . push ( ...errors ) ;
177+ }
169178
170179 return {
171180 error : makeError (
@@ -415,6 +424,7 @@ export function reportTranspileErrors(
415424 if ( ! instance . reportTranspileErrors ) {
416425 return ;
417426 }
427+ const module = loader . _module ;
418428 instance . reportTranspileErrors = false ;
419429 // happypack does not have _module.errors - see https://github.com/TypeStrong/ts-loader/issues/336
420430 if ( ! instance . loaderOptions . happyPackMode ) {
@@ -431,7 +441,15 @@ export function reportTranspileErrors(
431441 { file : instance . configFilePath || 'tsconfig.json' } ,
432442 loader . context
433443 ) ;
434- loader . _module . errors . push ( ...solutionErrors , ...errors ) ;
444+ /**
445+ * Since webpack 5, the `errors` property is deprecated,
446+ * so we can check if some methods for reporting errors exist.
447+ */
448+ if ( module . addError ) {
449+ [ ...solutionErrors , ...errors ] . forEach ( error => module . addError ( error ) ) ;
450+ } else {
451+ module . errors . push ( ...solutionErrors , ...errors ) ;
452+ }
435453 }
436454}
437455
0 commit comments