【问题标题】:error TS2307: Cannot find module '.shaders/vertex.glsl' or its corresponding type declarations错误 TS2307:找不到模块 '.shaders/vertex.glsl' 或其对应的类型声明
【发布时间】:2021-05-14 17:55:34
【问题描述】:

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

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

我的文件夹结构:

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

【问题讨论】:

  • 不应该是./shaders/vertex.glsl吗?您在提供的结构中的任何位置都没有名为 .shaders 的目录。
  • 确实如此。不幸的是,它仍然不起作用。

标签: typescript glsl tsconfig


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2021-11-23
    • 2021-08-27
    • 2022-10-17
    • 2021-04-08
    • 2022-10-06
    • 2021-12-21
    • 2021-04-15
    • 2023-01-31
    • 2020-11-17
    相关资源
    最近更新 更多