You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode中ts-node-dev输出的ProblemMatcher无法检测问题如何解决?

问题:VSCode无法识别ts-node-dev输出的problemMatcher匹配项

尝试为ts-node-dev的输出编写problemMatcher,但VSCode始终无法检测到输出中的错误。以下是终端输出示例:

Please migrate your code to use AWS SDK for JavaScript (v3).
For more information, check the migration guide at https://a.co/7PzMCcy
(Use `node --trace-warnings ...` to show where the warning was created)
[INFO] 15:58:00 Restarting: /Users/myname/dev/workspaces/ts_workspace/code/api/src/graphql/schemas/dataDiagnostic.ts has been modified
trying to use docker executor...but configured as cannot.
Error: Unknown type "DataDiagnosticSverity". Did you mean "DataDiagnosticSeverity", "DataDiagnosticEdge", "DataDiagnostic", or "DataDiagnosticConnection"?
    at assertValidSDL (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/graphql/validation/validate.js:135:11)
    at buildASTSchema (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/graphql/utilities/buildASTSchema.js:44:34)
    at makeExecutableSchema (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/@graphql-tools/schema/cjs/makeExecutableSchema.js:73:47)
    at Object.<anonymous> (/Users/myname/dev/workspaces/ts_workspace/code/api/src/apolloServer.ts:12:36)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Module._compile (/Users/myname/dev/workspaces/ts_workspace/code/node_modules/source-map-support/source-map-support.js:568:25)
    at Module.m._compile (/private/var/folders/fr/gxs3qpcs2zxby__p9lm9h_rm0000gn/T/ts-node-dev-hook-6064780755344261.js:69:33)
    at Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at require.extensions..jsx.require.extensions..js (/private/var/folders/fr/gxs3qpcs2zxby__p9lm9h_rm0000gn/T/ts-node-dev-hook-6064780755344261.js:114:20)
    at require.extensions.<computed> (/private/var/folders/fr/gxs3qpcs2zxby__p9lm9h_rm0000gn/T/ts-node-dev-hook-6064780755344261.js:71:20)
[ERROR] 15:58:01 Error: Unknown type "DataDiagnosticSverity". Did you mean "DataDiagnosticSeverity", "DataDiagnosticEdge", "DataDiagnostic", or "DataDiagnosticConnection"?
(node:54671) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023.

当前使用的problemMatcher配置:

"problemMatcher": [
  {
    "fileLocation": "absolute",
    "pattern": {
      "regexp": "^(Error|Warning):\\s*(.*)[\\n\\r]+\\s+at\\s+(.*)\\s+\\((.*):(\\d+):(\\d+)\\)",
      "severity": 1,
      "message": 2,
      "file": 4,
      "line": 5,
      "column": 6
    }
  }
]

已验证正则能匹配输出,但VSCode任务运行时无法检测到问题。


解决方案

VSCode的默认problemMatcher是逐行匹配的,原正则试图跨多行匹配错误行和堆栈行,不符合VSCode的匹配逻辑。需要改为多段式pattern配置,分两步匹配错误消息和对应的堆栈行:

修改后的problemMatcher配置:

"problemMatcher": [
  {
    "owner": "ts-node-dev",
    "fileLocation": "absolute",
    "pattern": [
      // 匹配错误消息行
      {
        "regexp": "^(Error|Warning):\\s*(.*)$",
        "severity": 1,
        "message": 2
      },
      // 匹配包含文件路径的堆栈行
      {
        "regexp": "^\\s+at\\s+\\S+\\s+\\((.*):(\\d+):(\\d+)\\)$",
        "file": 1,
        "line": 2,
        "column": 3
      }
    ]
  }
]

关键修改说明

  • 用pattern数组替代单pattern,实现分阶段匹配:第一阶段捕获错误级别和消息,第二阶段捕获对应的文件、行号、列号
  • 调整正则为单行匹配模式,符合VSCode的逐行处理逻辑
  • 添加owner字段标识匹配器归属,帮助VSCode区分不同来源的问题
  • 堆栈行正则匹配开头的缩进(^\s+),确保只匹配错误堆栈中的有效行

可选优化:添加applyTo: "allDocuments"字段,让问题能关联到所有打开的文档:

"problemMatcher": [
  {
    "owner": "ts-node-dev",
    "fileLocation": "absolute",
    "applyTo": "allDocuments",
    "pattern": [
      // 同上的pattern数组
    ]
  }
]

修改配置后重新运行任务,VSCode应能正确识别错误并在「问题」面板中显示,同时关联到对应的文件、行号位置。

内容的提问来源于stack exchange,提问作者Nate Glenn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 08:08:11