由于某种原因,我收到此错误
error TS2688: Cannot find type definition file for 'dist'
,尽管dist
是一个文件夹。有谁知道为什么会发生这种情况以及我可以采取什么措施来解决这个问题?
ts配置:
{
"compilerOptions": {
"target": "es5" ,
"lib": [
"es2019",
"dom"
],
"allowJs": false,
"declaration": true,
"sourceMap": true,
"outDir": "./dist/",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true ,
"noFallthroughCasesInSwitch": true,
"typeRoots": [
"./"
],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true ,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"compileOnSave": true,
"exclude": ["node_modules/"],
"include": ["main.ts"]
}
这是我的文件夹结构:
"typeRoots": [
"./"
],
您的 typeRoots 映射到您的根文件夹,因此它会认为
./dist
和 ./node_modules
将包含不正确的定义文件。我建议将其放在./typings
文件夹中以避免出现此问题。
glsl.d.ts
文件移动到名为 ./typings
['./typings']
tsc
,它就不再抱怨了我正在使用 NestJS,我的解决方案是添加
"typeRoots": [],
在tsconfig.json
。我无意中解决了这个问题,但不知道为什么会这样。