错误:没有注册任务类型“npm”。您是否错过了安装提供相应任务提供程序的扩展?

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

我已经安装了nodejs(node-v14.17.6-x64)并且正在使用reactjs。但是每当我尝试使用VS Code中的google chrome启动我的应用程序时,我都会收到此错误

找不到任务“npm:start”。

我可以使用该 url 启动该应用程序。为什么会出现这个问题?

当点击启动图标时

终端错误

期望:

我想使用 vscode 中的运行按钮启动我的应用程序

reactjs visual-studio-code npm
1个回答
0
投票

这是一个简单的解决方案。

这是一个简单的解决方案

我在开发 vsocde typescript 插件时也遇到了相同的错误输出 解决办法也很简单 问题显示为 '错误:没有注册任务类型'npm'您是否错过了安装提供相应任务提供程序的扩展`

这说明vscode无法执行type=npm的任务,但是如果我们已经将npm添加到环境变量中,就可以通过shell类型任务来实现这个任务

只需打开并修改

/ Vscode/tasks.json

这是我的示例或解决方案:

enter code here
 {
"version": "2.0.0",
"tasks": [
    //// when attempt to run the task, I encountered the same error output
    //// Error: there is no registered task type 'npm'. Did you miss installing an extension that provides a corresponding task provider?
    // { 
    //  "type": "npm",
    //  "script": "watch",
    //  "problemMatcher": "$tsc-watch",
    //  "isBackground": true,
    //  "presentation": {
    //      "reveal": "never"
    //  },
    //  "group": {
    //      "kind": "build",
    //      "isDefault": true
    //  }
    // },

     { // we can implement this task through shell type tasks as followed
        "label": "modyfied npm task",
        "type": "shell",
        "command":"npm",
        "args": ["run", "watch"], 
        "problemMatcher": "$tsc-watch",
        "isBackground": true,
        "presentation": {
            "reveal": "never"
        },
        "group": {
            "kind": "build",
            "isDefault": false,
        }
     }
    ]
}
© www.soinside.com 2019 - 2024. All rights reserved.