【问题标题】:Exclude node_modules from "problems"从“问题”中排除 node_modules
【发布时间】:2017-12-29 06:24:18
【问题描述】:

我正在运行这个任务:

{
        "taskName": "tsc watch",
        "command": "tsc -w",
        "type": "shell",
        "problemMatcher": "$tsc-watch"
}

使用这个 tsconfig:

{
    "compileOnSave": true,
    "files": [
        "src/index.ts"
    ],
    "compilerOptions": {
        "module": "commonjs",
        "sourceMap": true,
        "outDir": "dist/"
    },
    "exclude": [
        "node_modules"
    ]
}

文件index.ts只有一行:

console.log('Is it working?');

“问题”选项卡充满了来自随机 npm 模块的 HTML 相关警告。为什么?我该如何阻止它?

编辑1:
通过从资源管理器中排除 node_modules 文件夹,我设法找到了一个可行的方法:

/* settings.json */
{
    "files.exclude": {
        "**/node_modules": true
    }
}

但是这是一个 hack,我仍然想要一个正确的答案..

【问题讨论】:

    标签: typescript visual-studio-code tsconfig


    【解决方案1】:

    我也偶然发现了这个问题。 我找到的唯一解决方案是添加 skipLibCheck 选项并在我的 tsconfig.json 的 compilerOptions 中将其设置为 true:

    {
        "compilerOptions": {
            "target": "es5",
            "module": "commonjs",
            "moduleResolution": "node",
            "sourceMap": true,
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "removeComments": false,
            "noImplicitAny": false,
            "skipLibCheck": true,
            "rootDir": "client/app"
        },
        "exclude": [
            "client/node_modules/"
        ]
    }
    

    根据the doc,它将跳过对所有声明文件 (*.d.ts) 的类型检查,在我的例子中,这些文件是抛出警告的文件。

    【讨论】:

      【解决方案2】:

      您只需要一个tsconfig.json 和:

      {
          "compilerOptions": {
              "skipLibCheck": true,
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2020-03-20
        • 2018-11-04
        • 1970-01-01
        • 2018-12-10
        • 2019-11-11
        • 2016-01-05
        • 2016-09-15
        • 1970-01-01
        相关资源
        最近更新 更多