Ts-loader: The output of getCustomTransformers makes compiling fail when tsconfig.json contains rootDir.

Created on 9 Aug 2017  路  3Comments  路  Source: TypeStrong/ts-loader

versions:

"typescript": "~2.4.0",
"ts-loader": "^2.2.1",

The test code:

// webpack.config.js
// path: module.rules

      {
        test: /\.(ts|tsx)$/,
        include: paths.appSrc,
        loader: require.resolve('ts-loader'),
        options: {
          transpileOnly: true,
          getCustomTransformers: () => ({
            before: [ content => node => node ] // Issue caused by here!!!!!!!!!!
          }),
        },
      }

complier print:

error TS6059: File 'index.tsx' is not under 'rootDir' '/Users/Zheeeng/Workspace/project/src'. 'rootDir' is expected to contain all source files.

The tsconfig.json:

"compilerOptions": {
    "rootDir": "src"
}

Does the getCustomTransformers saved the temp content to other place and fails the compiling?

I encountered this issue while I'm using ts-import-plugin, and reported it at https://github.com/Brooooooklyn/ts-import-plugin/issues/5. After a simple test, I find it's something wrong with ts-loader.

Most helpful comment

This issue is actually cased by transpileOnly option.
if this option was passed to ts-loader, it would use ts.compiler.transpileModule.

Because of https://github.com/Microsoft/TypeScript/blob/master/src/services/transpile.ts#L92 and https://github.com/Microsoft/TypeScript/blob/master/src/compiler/program.ts#L1797
we shouldn't pass rootDir to compiler.transpileModule.

I will fix it later with a pull request.

All 3 comments

Do you have any ideas @longlho or @igorbek?

This issue is actually cased by transpileOnly option.
if this option was passed to ts-loader, it would use ts.compiler.transpileModule.

Because of https://github.com/Microsoft/TypeScript/blob/master/src/services/transpile.ts#L92 and https://github.com/Microsoft/TypeScript/blob/master/src/compiler/program.ts#L1797
we shouldn't pass rootDir to compiler.transpileModule.

I will fix it later with a pull request.

@Brooooooklyn Thx for your work.

Was this page helpful?
0 / 5 - 0 ratings