Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tsc not excluding npm linked node_modules

The problem: When type checking my app using tsc I am getting errors for npm linked modules.

Here is my type-check command:
"type-check": "tsc --noEmit -p tsconfig.json"

and here is my tsconfig.json:

{
    "compilerOptions": {
        "outDir": "./dist/",
        "sourceMap": true,
        "noImplicitAny": false,
        "allowJs": true,
        "module": "commonjs",
        "target": "es6",
        "jsx": "react",
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "skipLibCheck": true
        //"importsNotUsedAsValues": "error"
    },
    "exclude": ["./node_modules/*"] // I've also tried node_modules, /node_modules, node_modules/
}

The command will fail due to type errors in one of my node_modules which is connected via npm link.

Any way to exclude this module from type check


Edit:

I have also tried using a double globstar (**) e.g.

"exclude": ["./node_modules/**/*"]

and this gives me the same incorrect result.

like image 293
Uri Klar Avatar asked Feb 13 '26 18:02

Uri Klar


1 Answers

If you are using webpack try to add symlinks: false in resolve. That solved similar issue for me.

resolve: {
    // ...  
    symlinks: false,
},

If you are using purely tsc try (I haven't tried this):

preserveSymlinks: true
like image 75
José Quinto Zamora Avatar answered Feb 16 '26 07:02

José Quinto Zamora