tsc not excluding npm linked node_modules
Asked Answered
C

1

13

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.

Cher answered 18/5, 2020 at 5:41 Comment(4)
Double-check that tsc exists in your node_modules/.bin. If not - try and identify where it takes it from.Ebner
Did you find a solution for your problem. I'm facing the same one. I have a lib linked with npm link and tsc is no excluding such lib when type checking/compiling.Gallagher
Can't say i did :-/Cher
could you try this ? "exclude": ["**/node_modules/**/"]Slat
M
6

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
Methadone answered 29/9, 2021 at 10:43 Comment(1)
preserveSymlinks: true in tsconfig.json worked for me, thanks!Proteolysis

© 2022 - 2024 — McMap. All rights reserved.