Ken*_*Ken 7 node.js typescript tsd
我正在使用此处找到的出色的Express / Node / Typescript示例代码。它使用来自run.sh的以下命令来编译.ts代码:
./node_modules/.bin/tsc --sourcemap --module commonjs ./bin/www.ts
这按宣传的方式工作,但是我更喜欢使用tsconfig.json文件,tsc -p .但是,当我运行该命令时,我得到了很多TS2300: Duplicate identifier 'foo' errors时候tsc(错误?)尝试遍历./node_modulesand ./typings目录的信息。以下是我正在使用的tsconfig.json:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings"
]
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我正在使用tsc 1.7.3 FWIW。
jmu*_*sch 31
同样,我遇到了node_modules排斥问题。
这是一个笨手笨脚的解决方案,它会忽略所有*.d.ts文件。
我补充说compilerOptions:
"compilerOptions": {
"skipLibCheck": true,
...
}
Run Code Online (Sandbox Code Playgroud)
小智 18
我发现**/在要排除的目录之前添加两个星号和一个斜杠()可以解决问题,编辑文件tsconfig如下:
{
...
"exclude": [
"**/node_modules",
"**/typings"
]
...
}
Run Code Online (Sandbox Code Playgroud)
Sam*_*ade 14
好的,如果您已经尝试了其他所有方法,请检查代码库中是否存在导致“排除”代码的导入语句。如果您在 Typescript 作用域中包含一个从(例如)“compiled-src”导入文件的文件,那么所有导入的文件都会突然被包含在内。这可能会产生多米诺骨牌效应,使排除属性看起来没有受到尊重。
具体来说,我使用 intellisense 从我的代码库中自动导入某些内容,并且 intellisense 决定它更喜欢编译 src 中的文件而不是 typescript 文件。我没有注意到,过了很长时间才意识到发生了什么。
Typescript 将拉入import作为项目一部分的文件中的语句引用的任何路径。
如果您看到已“排除”的文件正在被处理,请检查其他代码中对它们的引用。
我做了:
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
Run Code Online (Sandbox Code Playgroud)
我创建了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"
]
}
Run Code Online (Sandbox Code Playgroud)
我跑了
[...]/Express-4x-Typescript-Sample$ tsc -p .
Run Code Online (Sandbox Code Playgroud)
它对我有用 - 即没有错误。
| 归档时间: |
|
| 查看次数: |
9961 次 |
| 最近记录: |