Skip to content

tsconfig paths resolution not working in v.1.1.0 #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kaykayehnn opened this issue Apr 21, 2019 · 10 comments
Closed

tsconfig paths resolution not working in v.1.1.0 #258

kaykayehnn opened this issue Apr 21, 2019 · 10 comments

Comments

@kaykayehnn
Copy link
Contributor

kaykayehnn commented Apr 21, 2019

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
@kaykayehnn kaykayehnn added the bug label Apr 21, 2019
@johnnyreilly
Copy link
Member

@johnnyreilly
Copy link
Member

johnnyreilly commented Apr 22, 2019

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.

@arcanis
Copy link
Contributor

arcanis commented Apr 22, 2019

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

@johnnyreilly
Copy link
Member

Thanks @arcanis! I really appreciate it ❤️

@arcanis
Copy link
Contributor

arcanis commented Apr 22, 2019

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.

@johnnyreilly
Copy link
Member

johnnyreilly commented Apr 22, 2019

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.

@arcanis
Copy link
Contributor

arcanis commented Apr 22, 2019

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 🙂

@johnnyreilly
Copy link
Member

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 😁

@arcanis
Copy link
Contributor

arcanis commented Apr 22, 2019

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,
})

@kaykayehnn
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants