如何从 TSC 中排除 node_modules 文件夹?

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

我知道这个问题之前已经被问过很多次了,但是到目前为止还没有解决方案对我有用。

这是我包含在我的

tsconfig
文件中的内容:

...
  "compilerOptions": {
    "skipLibCheck": true,
...
"exclude": ["node_modules/*"]

但是我的

node_modules
文件夹中的文件仍然出现 TS 错误。 将
"explainFiles": true
添加到配置中还可验证是否包含这些文件。

我错过了什么?

完整配置:

{
  "forceConsistentCasingInFileNames": true, // Disallow inconsistently-cased references to the same file
  "noImplicitReturns": true, // Report error when not all code paths in function return a value
  "noUnusedLocals": true, // Report errors on unused locals
  "compilerOptions": {
    "target": "es2015",
    "explainFiles": true,
    "allowJs": true,
    "checkJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "strict": false,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve",
    "lib": ["dom", "es2015", "es2020"],
    "baseUrl": "./",
    "paths": {
      "src/*": ["src/*"],
    },
    "types": ["jest", "chrome"]
  },
  "include": ["src", "test"],
  "exclude": ["node_modules"]
}
typescript tsc
1个回答
0
投票

您能否提供完整的 package.json 和 tsconfig.json 以便我们深入研究该问题?

根据您提供的内容以及对我有用的内容(根据我的经验),您可以:

  1. 清除打字稿编译器缓存并重建项目 - 您可能需要清除node_modules/.cache(只需删除它)和dist(或out)文件夹并再次重新编译ts

  2. 仔细检查您的 tsconfig.json 是否有任何错误

  3. 很简单,但请确保您的 tsconfig.json 位于根目录中并且被正确引用

我还在网上找到了这个,所以你可能想尝试一下 4. 如果 tsconfig.json 中有 "noImplicitAny": true,请考虑暂时将其设置为 false,看看是否可以解决问题

仅通过查看您提供的内容,我就想到了这些。

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