Fork-ts-checker-webpack-plugin: TypeError: Cannot read property 'context' of undefined

Created on 17 May 2018  路  10Comments  路  Source: TypeStrong/fork-ts-checker-webpack-plugin

Webpack v.4.8.3
Typescript v.2.3.4

D:\Projects\pl-webpack4\node_modules\fork-ts-checker-webpack-plugin\lib\index.js:130
        return path.isAbsolute(filePath) ? filePath : path.resolve(this.compiler.options.context, filePath);

                                                                                        ^
TypeError: Cannot read property 'context' of undefined

   at ForkTsCheckerWebpackPlugin.computeContextPath (D:\Projects\pl-webpack4\node_modules\fork-ts-checker-webpack-plugin\lib\index.js:130:89)
    at ForkTsCheckerWebpackPlugin.apply (D:\Projects\pl-webpack4\node_modules\fork-ts-checker-webpack-plugin\lib\index.js:86:34)
    at plugins.forEach.plugin (D:\Projects\pl-webpack4\node_modules\enhanced-resolve\lib\ResolverFactory.js:276:10)
    at Array.forEach (<anonymous>)
    at Object.exports.createResolver (D:\Projects\pl-webpack4\node_modules\enhanced-resolve\lib\ResolverFactory.js:275:10)
    at ResolverFactory._create (D:\Projects\pl-webpack4\node_modules\webpack\lib\ResolverFactory.js:57:28)
    at ResolverFactory.get (D:\Projects\pl-webpack4\node_modules\webpack\lib\ResolverFactory.js:50:28)
    at Compilation.buildModule (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compilation.js:365:25)
    at moduleFactory.create (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compilation.js:711:12)
    at MultiModuleFactory.create (D:\Projects\pl-webpack4\node_modules\webpack\lib\MultiModuleFactory.js:18:3)
    at semaphore.acquire (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compilation.js:658:18)
    at Semaphore.acquire (D:\Projects\pl-webpack4\node_modules\webpack\lib\util\Semaphore.js:17:4)
    at Compilation._addModuleChain (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compilation.js:657:18)
    at Compilation.addEntry (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compilation.js:741:8)
    at compiler.hooks.make.tapAsync (D:\Projects\pl-webpack4\node_modules\webpack\lib\MultiEntryPlugin.js:41:17)
    at AsyncParallelHook.eval [as callAsync] (eval at create (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:7:1)
    at AsyncParallelHook.lazyCompileHook [as _callAsync] (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at hooks.beforeCompile.callAsync.err (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:476:20)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at Compiler.compile (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:469:28)
    at readRecords.err (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:220:11)
    at Compiler.readRecords (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:342:11)
    at hooks.run.callAsync.err (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:217:10)
    at _err0 (eval at create (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:11:1)
    at compiler.hooks.run.tapAsync (D:\Projects\pl-webpack4\node_modules\webpack\lib\CachePlugin.js:46:60)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:7:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at hooks.beforeRun.callAsync.err (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:214:19)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:15:1)

If I set absolute path to tsconfig in options, than:

D:\Projects\pl-webpack4\node_modules\fork-ts-checker-webpack-plugin\lib\index.js:144
            this.compiler.hooks.run.tapAsync(checkerPluginName, run);

                                   ^
TypeError: Cannot read property 'tapAsync' of undefined
    at ForkTsCheckerWebpackPlugin.pluginStart (D:\Projects\pl-webpack4\node_modules\fork-ts-checker-webpack-plugin\lib\index.js:144:36)
    at ForkTsCheckerWebpackPlugin.apply (D:\Projects\pl-webpack4\node_modules\fork-ts-checker-webpack-plugin\lib\index.js:102:18)
    at plugins.forEach.plugin (D:\Projects\pl-webpack4\node_modules\enhanced-resolve\lib\ResolverFactory.js:276:10)
    at Array.forEach (<anonymous>)
    at Object.exports.createResolver (D:\Projects\pl-webpack4\node_modules\enhanced-resolve\lib\ResolverFactory.js:275:10)
    at ResolverFactory._create (D:\Projects\pl-webpack4\node_modules\webpack\lib\ResolverFactory.js:57:28)
    at ResolverFactory.get (D:\Projects\pl-webpack4\node_modules\webpack\lib\ResolverFactory.js:50:28)
    at Compilation.buildModule (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compilation.js:365:25)
    at moduleFactory.create (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compilation.js:711:12)
    at MultiModuleFactory.create (D:\Projects\pl-webpack4\node_modules\webpack\lib\MultiModuleFactory.js:18:3)
    at semaphore.acquire (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compilation.js:658:18)
    at Semaphore.acquire (D:\Projects\pl-webpack4\node_modules\webpack\lib\util\Semaphore.js:17:4)
    at Compilation._addModuleChain (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compilation.js:657:18)
    at Compilation.addEntry (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compilation.js:741:8)
    at compiler.hooks.make.tapAsync (D:\Projects\pl-webpack4\node_modules\webpack\lib\MultiEntryPlugin.js:41:17)
    at AsyncParallelHook.eval [as callAsync] (eval at create (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:7:1)
    at AsyncParallelHook.lazyCompileHook [as _callAsync] (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at hooks.beforeCompile.callAsync.err (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:476:20)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:6:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at Compiler.compile (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:469:28)
    at readRecords.err (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:220:11)
    at Compiler.readRecords (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:342:11)
    at hooks.run.callAsync.err (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:217:10)
    at _err0 (eval at create (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:11:1)
    at compiler.hooks.run.tapAsync (D:\Projects\pl-webpack4\node_modules\webpack\lib\CachePlugin.js:46:60)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:7:1)
    at AsyncSeriesHook.lazyCompileHook [as _callAsync] (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\Hook.js:35:21)
    at hooks.beforeRun.callAsync.err (D:\Projects\pl-webpack4\node_modules\webpack\lib\Compiler.js:214:19)
    at AsyncSeriesHook.eval [as callAsync] (eval at create (D:\Projects\pl-webpack4\node_modules\webpack\node_modules\tapable\lib\HookCodeFactory.js:24:12), <anonymous>:15:1)

Most helpful comment

@kodemi I ran into the same issue, and it turned out I accidentally put the plugin in webpack.resolve.plugins instead of webpack.plugins. Moving it to the correct array in my webpack config resolved the issue for me!

All 10 comments

@kodemi Did you solve this issue?

No, I don鈥檛.

Do you have a reproduction repo?

@kodemi I ran into the same issue, and it turned out I accidentally put the plugin in webpack.resolve.plugins instead of webpack.plugins. Moving it to the correct array in my webpack config resolved the issue for me!

Thanks for reporting back! Super helpful for others 馃尰鈾ワ笍

I'm having a similar issue. trying to put together a repo for you guys.

TypeError: Cannot read property 'options' of undefined
    at ForkTsCheckerWebpackPlugin.computeContextPath (/Users/michael.eatherly/workspace/compass/node_modules/fork-ts-checker-webpack-plugin/src/index.ts:132:25)
    at ForkTsCheckerWebpackPlugin.apply (/Users/michael.eatherly/workspace/compass/node_modules/fork-ts-checker-webpack-plugin/src/index.ts:258:21)

This is happening on version 1.0.0 for me. If I switch to version 0.5.2 it goes away.
put if I manually set the tsconfig option with: path.resolve("./tsconfig.json") it works. but this is because it doesn't call this.compiler.options lol

Also I'm using a mono repo with extends in my tsconfig.json. not sure if that's a problem either.

Hopefully I can create a test repo to recreate the problem.

Might be worth you checking out the various alpha versions of the plugin so you can narrow down when the problem arose

See details of versions here: https://github.com/Realytics/fork-ts-checker-webpack-plugin/blob/master/CHANGELOG.md

Could be this: https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/214

@johnnyreilly Ah! thanks I didn't think about doing that and I had ^ on my package.json 馃
I started testing it and it was working all the way up until v1.0.0-alpha.5 so that's the culprit!
Thanks for your help!! I'll continue to use v1.0.0-alpha.4 until I or someone has time to dig into the issue.

Awesome - if you did get the chance to look into this I'd greatly appreciate it. I'm guessing the issue lies somewhere in here: https://github.com/Realytics/fork-ts-checker-webpack-plugin/pull/204/files (the PR that lead to 1.0.0-alpha.5)

Was this page helpful?
0 / 5 - 0 ratings