问题
I am going nuts currently why my typescript compilation (tsc) is always trying to compile node_modules files even when I've specified to exclude this folder.
[tl;dr; : it's because I have imports but I don't know how to exclude imports from compilation]
I'm using Visual Studio Code, but have the same issue when running tsc directly from commandline
My project structure is a typical one :
.
|
--node_modules\..
|
--src\..
|
--typings
In my root I have a tsconfig.json with following content:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"sourceMap": false,
"watch": false
},
"compileOnSave": true,
"exclude":
[
"node_modules"
]
}
But when I compile (using tsc directly in commandline or through visual studio code) I see a zillion of errors from \node_modules\angular..
Now, I do use import statements in my typescript files (because I want to use webpack in the end):
import * as angular from 'angular';
import router from 'angular-ui-router';
So, it seems the typescript compiler tries to import these angular modules AND compile...
I tried to use the --noResolve option in the tsconfig.json, but then my source files throw errors that they cannot find these modules..
I there any way I can tell the typescript compiler to not compile imported modules from folder xyz ?
回答1:
In the end, my solution was not by adjusting my tsconfig.json file, but to call the compiler with the new --skipLibCheck flag (added in TypeScript 2.0 - see here in the typescript wiki)
>tsc --skipLibCheck
I also removed the exclude property from my tsconfig.json (as the "exclude" property defaults to excluding the node_modules anyway when not specified (see in the typescript docs).
来源:https://stackoverflow.com/questions/40547903/tsconfig-js-exclude-property-not-working-when-import-modules-is-used