Bri*_*Law 16 typescript tsc tsconfig
运行 tsc 时,我得到许多TS2688: Cannot find type definition file for 'someLibrary'
这些库来自node_modules. 我尝试在 tsconfig 中排除node_modules和skipLibCheck,但它们都不适合我。知道为什么会发生这种情况吗?
这是我的 tsconfig.json
{
"ts-node": {
"files": true,
"emit": true,
"compilerHost": true
},
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"target": "es2016",
"sourceMap": true,
"typeRoots" : ["./node_modules","./node_modules/@types"],
"jsx": "react",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "commonJS",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
Bri*_*Law 14
问题是错了typeRoots。应该使用默认的./node_modules/@types
小智 6
默认情况下,ts.config.json您已放入 typeRoots 。像这样:
"compilerOptions": {
...
"typeRoots": ["./node_modules/@types"]
}
Run Code Online (Sandbox Code Playgroud)