【问题标题】:vscode intellisense - cannot find module ts(2307) in excluded directoryvscode intellisense - 在排除目录中找不到模块 ts(2307)
【发布时间】:2022-07-25 03:06:08
【问题描述】:

在我的 tsconfig.json 中,我排除了文件夹

"src/__test__"

来自编译。现在的问题是 VS Code 找不到模块。我用 Jest 运行测试没有问题,模块已解决,但此消息很烦人。我也不能使用自动完成。 有没有办法为测试和源代码创建单独的打字稿配置文件?到目前为止,我使用 "extend": "../../tsconfig.json" 创建了 tsconfig.test.json 文件,但它没有按我的预期工作。编译器只读基 tsconfig.json。

找不到模块 <..> 或其对应类型 声明.ts(2307)

tsconfig.json

{
      "compilerOptions": {
        "module": "esnext",
        "esModuleInterop": true,
        "target": "es5",
        "lib": ["es6", "dom"],
        "sourceMap": false,
        "allowJs": true,
        "jsx": "react",
        "moduleResolution": "node",
        "rootDir": "",
        "allowSyntheticDefaultImports": true,
        "forceConsistentCasingInFileNames": true,
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "noImplicitAny": true,
        "strictNullChecks": true,
        "suppressImplicitAnyIndexErrors": true,
        "noUnusedLocals": true,
        "baseUrl": ".",
        "outDir": "dist",
        "resolveJsonModule": true,
        "paths": {
          "components/*": ["src/components/*"],
          "utils/*": ["src/utils/*"],
          "api/*": ["src/api/*"],
          "src/*": ["src/*"]
        }
      },
      "exclude": ["src/__tests__"]
    }

【问题讨论】:

    标签: typescript visual-studio-code tsconfig


    【解决方案1】:

    我找到了解决方法。

    通过添加这行代码,您将阻止 jest 在 dist 文件夹中运行 *test.js 文件:

    {
        ...,
        testPathIgnorePatterns: [
          "<rootDir>/dist/"
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-05
      • 2020-07-22
      • 2019-08-23
      • 2020-09-22
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      • 1970-01-01
      • 2021-10-16
      相关资源
      最近更新 更多