错误 TS2307:找不到模块“.shaders/vertex.glsl”或其相应的类型声明

时间:2021-02-11 00:33:13

标签: typescript glsl tsconfig

目前我在尝试将一些文件作为字符串导入我的 main.ts 时遇到以下错误。

main.ts:2:21 - error TS2307: Cannot find module './shaders/vertex.glsl' or its corresponding type declarations.
main.ts:3:21 - error TS2307: Cannot find module './shaders/fragment.glsl' or its corresponding type declarations.

main.ts:

// shader
import vsource from ".shaders/vertex.glsl";
import fsource from ".shaders/fragment.glsl";

typings/glsl.d.ts:

declare module "*.glsl" {
    const value: string;
    export default value;
}

tsconfig:

{
    "compilerOptions": {
        /* Visit https://aka.ms/tsconfig.json to read more about this file */

        /* Basic Options */
        "target": "es5",
        "lib": [
            "es2019",
            "dom"
        ] ,
        "allowJs": false,
        "declaration": true,
        "sourceMap": true,
        "outDir": "./dist/",
        "strict": true,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "strictFunctionTypes": true,
        "strictBindCallApply": true,
        "strictPropertyInitialization": true,
        "noImplicitThis": true,
        "alwaysStrict": true,

        "noUnusedLocals": false,      
        "noUnusedParameters": false,  
        "noImplicitReturns": true,
        "noFallthroughCasesInSwitch": true ,
        "typeRoots": [
            "./typings"
        ],
        "allowSyntheticDefaultImports": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true 
    },
    "compileOnSave": true,
    "include": ["main.ts"]
}

我的文件夹结构:

my folder structure

有谁知道为什么会出现这个错误以及我该如何解决?

1 个答案:

答案 0 :(得分:0)

我删除了 "include": ["main.ts"],现在它可以工作了。有人告诉我,添加 main.ts 会使 main.ts 成为唯一被编译的文件。