fork-ts-checker-webpack-plugin: TypeError: Cannot read property '0' of undefined

The plugin crashed right after rebuilding (in watch mode), with below message

/~/node_modules/fork-ts-checker-webpack-plugin/lib/index.js:323
            var elapsed = Math.round(_this.elapsed[0] * 1E9 + _this.elapsed[1]);
                                                  ^

TypeError: Cannot read property '0' of undefined
    at ForkTsCheckerWebpackPlugin.doneCallback (~node_modules/fork-ts-checker-webpack-plugin/lib/index.js:323:51)
    at ForkTsCheckerWebpackPlugin.handleServiceMessage (/~/node_modules/fork-ts-checker-webpack-plugin/lib/index.js:273:52)
    at ChildProcess.<anonymous> (/Users/rok/GitHub/sinicompany/closer-www/node_modules/fork-ts-checker-webpack-plugin/lib/index.js:231:70)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at emit (internal/child_process.js:772:12)
    at _combinedTickCallback (internal/process/next_tick.js:141:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

version

webpack 3.8.1 webpack-dev-server 2.9.4 fork-ts-checker-plugin 0.2.9 typescirpt 2.6.1 tslint 5.8.0 tslint-microsoft-contrib 5.0.1

options

fork-ts-checker-plugin

{
  "tsconfig": "../tsconfig.json",
  "tslint": "../tslint.json",
  "checkSyntacticErrors": true,
}

tsconfig

{
  "compilerOptions": {
    "sourceMap": true,
    "target": "es5",
    "jsx": "react",
    "module": "esnext",
    "moduleResolution": "node",
    "allowJs": false,
    "importHelpers": true,
    "emitDecoratorMetadata": false,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "downlevelIteration": true,
    "pretty": true,
    "declaration": false,
    "noUnusedLocals": true,
    "noUnusedParameters": false,
    "noImplicitAny": false,
    "noImplicitReturns": false,
    "removeComments": false,
    "strictNullChecks": false,
    "outDir": "dist",
    "baseUrl": ".",
    "paths": {
      "*": ["src/*", "*"]
    },
    "lib": [
      "es6",
      "es7",
      "dom"
    ]
  },
  "exclude": [
    "dist",
    "node_modules"
  ]
}

tslint

{
  "rulesDirectory": [
    "node_modules/tslint-microsoft-contrib"
  ],
  ...
}

it works well with fork-ts-checker-plugin@0.2.8.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 20 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@johnnyreilly I’m using the Chrome inspector to walk through some of the code. It looks like this.elapsed is initially set. However, when createDoneCallback() is called, elapsed is not defined. In other words, handleServiceMessage() is called after createDoneCallback() and I believe after a child process is spun off. handleServiceMessage() does define elapsed on this, but _this in createDoneCallback() is never updated.

Presumably, createDoneCallback()'s _this and handleServiceMessage()'s this refer to different this objects. I wonder if that has anything to do with child-process. Perhaps handleServiceMessage() is being called in a child process and not modifying the same this?

However, this does have elapsed defined within the done callback defined by createDoneCallback() (but not _this).

The solution I found was to use this instead of _this in the callback created by createDoneCallback().

Great - I’ll submit a PR. Thanks!