wbuchwalter / tslint-loader

tslint loader for webpack
193 stars 65 forks source link

Type checking module build fails when consuming TS files from an `npm link`ed package #96

Closed ceszare closed 6 years ago

ceszare commented 6 years ago

First of all, thank you so much for providing a very useful loader. For the most part it works really well, and has boosted my productivity substantially. I am having a problem, and would definitely appreciate your input in trying to figure out a fix/workaround, or guidance in the case I may be doing something wrong.

I have an npm package (A) that hosts an app that is bundled via webpack. When adding tslint-loader to my webpack builds, it works nicely.

Separately, I have a library as an npm package (B) that A consumes. Oftentimes, I may do development with both of them at the same time. I will use npm link to create a symlink between B and its independency inside A's node_modules folder. This workflow does not work for tslint-loader, as I get the following error:

ERROR in ../relative/path/to/failing/typescript/file.ts
Module build failed: FatalError:
Invalid source file: /Absolute/path/to/failing/typescript/file.ts. Ensure that the files supplied to lint have a .ts, .tsx, .d.ts, .js or .jsx extension.

    at new FatalError (/Absolute/path/to/package/A/node_modules/tslint/lib/error.js:27:28)
    at Linter.getSourceFile (/Absolute/path/to/package/A/node_modules/tslint/lib/linter.js:222:23)
    at Linter.lint (/Absolute/path/to/package/A/node_modules/tslint/lib/linter.js:96:31)
    at lint (/Absolute/path/to/package/A/node_modules/tslint-loader/index.js:70:10)
    at Object.module.exports (/Absolute/path/to/package/A/node_modules/tslint-loader/index.js:140:3)
 @ ../relative/path/to/failing/typescript/file.ts 22:0-45

The error in the linters only happens when I have type-checking enabled.

The error doesn't happen if I run the tslint command directly, i.e.

tslint -c tslint.json -p tsconfig.json \"src/**/*.ts\"

The loader is using the same tslint.json and tsconfig.json files.

Let me know if I could provide more information.

andrew0r commented 6 years ago

I just ran into this same situation. I found the hint to solve it at https://github.com/palantir/tslint/issues/2208

The fix that I found was to add to my tsconfig.json a section that looked like:

"include": [
  "./src/**/*",
  "../my-linked-module/src/**/*"
],

Good luck!

ceszare commented 6 years ago

This makes a lot of sense. Thanks for the tip! 👍