首页 > 解决方案 > 错误 TS2307:找不到模块 '.shaders/vertex.glsl' 或其对应的类型声明

问题描述

目前,我尝试将一些文件作为字符串导入到我的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";

打字/glsl.d.ts:

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

配置:

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

我的文件夹结构:

我的文件夹结构

有谁知道为什么会发生此错误以及如何解决?

标签: typescriptglsltsconfig

解决方案


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


推荐阅读