VS Code调试Vue.js报错:无法跟踪‘vuejs: start’任务
报错原因及解决方案
报错原因
你在tasks.json中将任务设置为isBackground: true,但未配置problemMatcher。VS Code需要通过problemMatcher来识别后台任务的启动状态(比如何时完成编译、进入稳定运行),没有这个配置的话,VS Code无法跟踪该后台任务的执行状态,因此抛出The task 'vuejs: start' cannot be tracked. Make sure to have a problem matcher defined.错误。
解决方案
给vuejs: start任务添加适配Vue CLI serve命令的problemMatcher,让VS Code能准确识别任务启动完成的信号。修改后的tasks.json如下:
{ "version": "2.0.0", "tasks": [ { "label": "vuejs: start", "type": "npm", "script": "serve", "isBackground": true, "problemMatcher": { "owner": "vue", "fileLocation": "absolute", "pattern": { "regexp": "^.*(Compiled successfully|Failed to compile).*$", "message": "$1" }, "background": { "activeOnStart": true, "beginsPattern": "^.*Starting development server.*$", "endsPattern": "^.*Compiled successfully.*$" } } } ] }
配置说明
beginsPattern:匹配Vue CLI启动时的Starting development server...日志,标记任务开始执行endsPattern:匹配编译成功的Compiled successfully日志,标记任务已准备就绪,VS Code可以继续启动调试流程pattern:用于捕获编译成功或失败的日志信息,辅助VS Code识别任务状态
内容的提问来源于stack exchange,提问作者DrJubbs
相关产品推荐
相关产品推荐

