Fork-ts-checker-webpack-plugin: Use with Nuxt.js throws Cannot read property 'options' of undefined

Created on 20 Mar 2019  路  3Comments  路  Source: TypeStrong/fork-ts-checker-webpack-plugin

When I use the plugin with Nuxt (https://nuxtjs.org/), this error is thrown.

Cannot read property 'options' of undefined 09:38:33

at ForkTsCheckerWebpackPlugin.computeContextPath (node_modules/fork-ts-checker-webpack-plugin/lib/index.js:28:42)
at ForkTsCheckerWebpackPlugin.apply (node_modules/fork-ts-checker-webpack-plugin/lib/index.js:127:34)
at webpack (node_modules/webpack/lib/webpack.js:47:13)
at compilers.compilersOptions.map (node_modules/@nuxt/webpack/dist/webpack.js:5187:24)
at Array.map ()
at WebpackBundler.build (node_modules/@nuxt/webpack/dist/webpack.js:5186:39)
at Builder.build (node_modules/@nuxt/builder/dist/builder.js:5518:30)

The function computeContextPath is defined inside the constructor like this:

    this.computeContextPath = (filePath) => path.isAbsolute(filePath)
        ? filePath
        : path.resolve(this.compiler.options.context, filePath);

The issue is resolved if the function is defined on the class itself, outside the constructor:

computeContextPath(filePath) {
    return path.isAbsolute(filePath)
        ? filePath
        : path.resolve(this.compiler.options.context, filePath);
}

Would you accept a PR for this, or do you think the solution for this error lies with Nuxt?

This is my Nuxt config:

import ForkTsChecker from "fork-ts-checker-webpack-plugin"

export default {
  build: {
    loaders: {
      ts: {
        transpileOnly: true
      }
    },
    plugins: [
      new ForkTsChecker()
    ]
  }
}

Most helpful comment

Nuxt-ts (Nuxt with TS) supports the plugin out of the box.. https://nuxtjs.org/api/configuration-build/#useforktschecker.

So.. it seems no fix is required!

All 3 comments

Yup we'd be open to a PR! Could you provide a test as well so we don't break this in future please?

The test should ideally not include nuxt - I think this a more general problem

Yes, I will have to see how Nuxt invokes webpack from their builder and mimic that.

Nuxt-ts (Nuxt with TS) supports the plugin out of the box.. https://nuxtjs.org/api/configuration-build/#useforktschecker.

So.. it seems no fix is required!

Was this page helpful?
0 / 5 - 0 ratings