Fork-ts-checker-webpack-plugin: tsconfig paths resolution not working in v.1.1.0

Created on 21 Apr 2019  路  10Comments  路  Source: TypeStrong/fork-ts-checker-webpack-plugin

Current behavior

Path aliases specified in tsconfig are not resolved, resulting in resolution errors.

Expected behavior

TS path aliases are resolved as in previous versions. The issue is not present in v1.0.4

Issue reproduction repository

https://github.com/kaykayehnn/fork-ts-checker-webpack-plugin-paths-bug

Steps to reproduce the issue

npm install
npm start

Environment

  • fork-ts-checker-webpack-plugin: ^1.1.0
  • typescript: ^3.4.4
  • tslint: none
  • webpack: ^4.30.0
  • os: macOS 10.14.4
bug help wanted

Most helpful comment

Yup! In the meantime I opened #260 with a fix.

To people affected by this bug, you can workaround it right now by disabling the incremental API:

new ForkTsCheckerWebpackPlugin({
  useTypescriptIncrementalApi: false,
})

All 10 comments

Tried the plugin. It didn't work. I believe this is a regression.

Given the nature of the issue is paths resolution, that's definitely something we want to get right for both PnP and not 馃榿

Anyone bumping on this should pin to 1.0.4 for now. Apologies for the disruption.

If @arcanis gets a chance to look at this then hopefully we can get a fix in. Otherwise I'll look at potentially reverting the changes for 1.1.0 for now, and adding a test for paths resolution so we don't break this in future.

Oh no! Will take a look today, thanks for the repro repo!

Thanks @arcanis! I really appreciate it 鉂わ笍

To be sure: even in 1.0.4 the plugin is meant to be required, right? I tried downgrading on the repro repo with the same error.

Interesting. I didn't try downgrading to 1.0.4 - just adding in https://www.npmjs.com/package/tsconfig-paths-webpack-plugin - thinking that was the issue.

I just tried downgrading to 1.0.4 and the same error presents. My package.json looks like this:

{
  "name": "fork-ts-checker-webpack-plugin-paths-bug",
  "scripts": {
    "start": "webpack"
  },
  "devDependencies": {
    "fork-ts-checker-webpack-plugin": "1.0.4",
    "ts-loader": "^5.3.3",
    "tsconfig-paths-webpack-plugin": "^3.2.0",
    "typescript": "^3.4.4",
    "webpack": "^4.30.0",
    "webpack-cli": "^3.3.0"
  }
}

My webpack.config.js looks like this:

var ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');

var webpackConfig = {
  mode: 'none',
  context: __dirname, // to automatically find tsconfig.json
  entry: './src/index.ts',
  resolve: {
    extensions: ['.ts']
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        options: {
          // disable type checker - we will use it in fork plugin
          transpileOnly: true
        }
      }
    ]
  },
  resolve: {
    plugins: [new TsconfigPathsPlugin({ /*configFile: "./path/to/tsconfig.json" */ })]
  },
  plugins: [
    new ForkTsCheckerWebpackPlugin({
      // Neither of the following solves the issue:
      // tsconfig: './tsconfig.json'
      // tsconfig: require('path').join(__dirname, './tsconfig.json')
    })
  ]
}

module.exports = webpackConfig

Given there's 2 thumbs up for this issue I think we are likely to have a regression.

@kaykayehnn it looks like your repro repo might be problematic - can you take a look please? Ideally it should work with 1.0.4 and break with 1.1.0. That isn't the case right now.

It seems like there's a design flaw in the TS resolveModuleNames API. The options parameter is required to call ts.resolveModuleName, but it's never passed to host.resolveModuleNames.

The documentation seems to directly pass the options used for createProgram, but that doesn't seem work with createWatchProgram which creates the options itself. As a result the options are currently empty - so no paths settings.

Still hoping to find a workaround, just wanted to share some context 馃檪

That's really helpful! The output of this could be us opening an issue with the TypeScript repo and seeing if it's possible that could change. Fingers crossed that isn't necessary but it's worth trying. They are helpful and wonderful people 馃榿

Yup! In the meantime I opened #260 with a fix.

To people affected by this bug, you can workaround it right now by disabling the incremental API:

new ForkTsCheckerWebpackPlugin({
  useTypescriptIncrementalApi: false,
})

Sorry about the repo, I hadn't added tsconfig-paths-webpack-plugin. Now it should be working with 1.0.4 and throw with 1.1.0

Was this page helpful?
0 / 5 - 0 ratings