Skip to content

Commit df98e98

Browse files
authored
Merge pull request #385 from TypeStrong/fix/issue-363
fix: prevent null-pointer error after killing child process
2 parents 6ee3d7a + 642b5bf commit df98e98

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,12 @@ class ForkTsCheckerWebpackPlugin {
489489

490490
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
491491
this.serviceRpc = new RpcProvider(message => this.service!.send(message));
492-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
493-
this.service.on('message', message => this.serviceRpc!.dispatch(message));
492+
this.service.on('message', message => {
493+
if (this.serviceRpc) {
494+
// ensure that serviceRpc is defined to avoid race-conditions
495+
this.serviceRpc.dispatch(message);
496+
}
497+
});
494498

495499
const forkTsCheckerHooks = ForkTsCheckerWebpackPlugin.getCompilerHooks(
496500
this.compiler
@@ -515,6 +519,8 @@ class ForkTsCheckerWebpackPlugin {
515519
this.cancellationToken.cleanupCancellation();
516520
}
517521

522+
// clean-up listeners
523+
this.service.removeAllListeners();
518524
this.service.kill();
519525
this.service = undefined;
520526
this.serviceRpc = undefined;

0 commit comments

Comments
 (0)