错误 TS2688:找不到“dist”的类型定义文件

问题描述 投票:0回答:2

由于某种原因,我收到此错误

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"]
}

这是我的文件夹结构:

typescript tsconfig
2个回答
4
投票
"typeRoots": [
     "./"
],

您的 typeRoots 映射到您的根文件夹,因此它会认为

./dist
./node_modules
将包含不正确的定义文件。我建议将其放在
./typings
文件夹中以避免出现此问题。

  • 将您的
    glsl.d.ts
    文件移动到名为
    ./typings
  • 的文件夹
  • 将 typeRoots 值更改为
    ['./typings']
  • 运行
    tsc
    ,它就不再抱怨了

0
投票

我正在使用 NestJS,我的解决方案是添加

 "typeRoots": [],
tsconfig.json
。我无意中解决了这个问题,但不知道为什么会这样。

© www.soinside.com 2019 - 2024. All rights reserved.