Skip to content

Commit 6d8d601

Browse files
authored
Fixed deprecation warnings on webpack@5. (#1195)
* Fixed deprecation warnings on webpack@5. Fixed #1194 * Removed redundant `!!` in `module.addError` checks * Version update to 8.0.5
1 parent cafc933 commit 6d8d601

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v8.0.5
4+
* [Fixed deprecation warnings on webpack@5](https://github.com/TypeStrong/ts-loader/issues/1194) - thanks @sanex3339
5+
36
## v8.0.4
47
* [Uses existing instance if config file is same as already built solution](https://github.com/TypeStrong/ts-loader/pull/1177) - thanks @sheetalkamat
58

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ts-loader",
3-
"version": "8.0.4",
3+
"version": "8.0.5",
44
"description": "TypeScript loader for webpack",
55
"main": "index.js",
66
"types": "dist",

src/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ function getTranspilationEmit(
632632
reportDiagnostics: true,
633633
fileName,
634634
});
635+
const module = loaderContext._module;
635636

636637
addDependenciesFromSolutionBuilder(instance, fileName, file =>
637638
loaderContext.addDependency(path.resolve(file))
@@ -644,11 +645,19 @@ function getTranspilationEmit(
644645
instance.loaderOptions,
645646
instance.colors,
646647
instance.compiler,
647-
{ module: loaderContext._module },
648+
{ module },
648649
loaderContext.context
649650
);
650651

651-
loaderContext._module.errors.push(...errors);
652+
/**
653+
* Since webpack 5, the `errors` property is deprecated,
654+
* so we can check if some methods for reporting errors exist.
655+
*/
656+
if (module.addError) {
657+
errors.forEach(error => module.addError(error));
658+
} else {
659+
module.errors.push(...errors);
660+
}
652661
}
653662

654663
return { outputText, sourceMapText };

src/instances.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)