typescript tsconfig.json 的“排除”属性不被尊重
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34312252/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"exclude" property of tsconfig.json is not being respected
提问by Ken
I am working with the excellent Express/Node/Typescript example code found here. It transpiles the .ts code with the following command from run.sh:
我正在使用此处找到的优秀 Express/Node/Typescript 示例代码。它使用 run.sh 中的以下命令转换 .ts 代码:
./node_modules/.bin/tsc --sourcemap --module commonjs ./bin/www.ts
./node_modules/.bin/tsc --sourcemap --module commonjs ./bin/www.ts
This works as advertised, but I would prefer to use a tsconfig.json file and tsc -p .
However, when I run that command I get a raft of TS2300: Duplicate identifier 'foo' errors
when tsc
(erroneously?) tries to walk the ./node_modules
and ./typings
directories. Below is the tsconfig.json I am using:
此作品为标榜,但我宁愿使用tsconfig.json文件,tsc -p .
然而,当我运行该命令我得到的木筏TS2300: Duplicate identifier 'foo' errors
时tsc
(误?)试图行走./node_modules
和./typings
目录。下面是我正在使用的 tsconfig.json:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings"
]
}
Any ideas? I am using tsc 1.7.3 FWIW.
有任何想法吗?我正在使用 tsc 1.7.3 FWIW。
采纳答案by Martin Vseticka
I did:
我做了:
git clone https://github.com/czechboy0/Express-4x-Typescript-Sample.git
cd Express-4x-Typescript-Sample/
./run.sh
tsd install # I don't know why, but this helped me.
./run.sh
I created Express-4x-Typescript-Sample/tsconfig.json
file with content
我创建了Express-4x-Typescript-Sample/tsconfig.json
包含内容的文件
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings"
]
}
I ran
我跑了
[...]/Express-4x-Typescript-Sample$ tsc -p .
and it works work me - i.e. there are no errors.
它对我有用 - 即没有错误。
回答by jmunsch
In a similar vein I was having issues with node_modules
exclusion.
同样,我遇到了node_modules
排斥问题。
Here's a heavy handed solution, that ignores all *.d.ts
files.
这是一个笨手笨脚的解决方案,它忽略所有*.d.ts
文件。
I added to compilerOptions
:
我补充说compilerOptions
:
"compilerOptions": {
"skipLibCheck": true,
...
}
回答by LDJ
I just had the same problem. Pulling my hair out for about 30 mins then discovered that if I change:
我只是遇到了同样的问题。拉我头发大约30分钟然后发现如果我改变:
"target": "ES5",
to
到
"target": "ES6",
All the errors go away!
所有的错误都消失了!
Anyone know why?!?
有谁知道为什么?!
回答by user3428449
I had this issue and my exclude
looked like this:
我有这个问题,我exclude
看起来像这样:
"exclude": [
"node_modules",
"typings"
]
When I removed the "typings"
it worked. Final solution for me:
当我删除"typings"
它时,它起作用了。我的最终解决方案:
"exclude": [
"node_modules"
]
回答by emery.noel
04/02/0217 (april 2) - I was going through this same thing, spent almost a full weekend on it. Finally I found this website (which I have never seen linked from any stackoverflow post): https://angular.io/docs/ts/latest/guide/typescript-configuration.html
04/02/0217(4 月 2 日) - 我正在经历同样的事情,几乎花了一个完整的周末。最后我找到了这个网站(我从未见过任何 stackoverflow 帖子的链接):https: //angular.io/docs/ts/latest/guide/typescript-configuration.html
In it, I found this line, right in the compilerOptions:
在其中,我在 compilerOptions 中找到了这一行:
"lib": [ "es2015", "dom" ]
I have no idea what it does, and at this point I don't care, but ALL of my node_modules errors went away.
我不知道它是做什么的,此时我不在乎,但是我所有的 node_modules 错误都消失了。
As for include/exclude not working, I believe it is because of "dependencies." Even if you exclude a folder, if an imported file (like Component or NgModule) has some dependency on a file in node_modules, tsc is going to try to compile that file.
至于包含/排除不起作用,我相信这是因为“依赖性”。即使您排除了一个文件夹,如果导入的文件(如 Component 或 NgModule)对 node_modules 中的文件有一些依赖性,tsc 也会尝试编译该文件。