简体   繁体   English

typescript 中的 VS 代码扩展“HelloWorld”示例不起作用

[英]VS code extension "HelloWorld" sample in typescript is not working

I'm trying to create VS code extension and followed the steps provided in documentation here我正在尝试创建 VS 代码扩展并按照此处文档中提供的步骤操作

I setup "helloworld" project in typescript but when i press "F5", nothing happening.我在 typescript 中设置了“helloworld”项目,但是当我按“F5”时,没有任何反应。 I saw, typescript files complied to JS but project is not opening new instance of VS code and enable debug mode not enabled on "F5".我看到,typescript 个文件符合 JS,但项目没有打开 VS 代码的新实例,并且启用未在“F5”上启用的调试模式。

Any suggestions?.有什么建议么?。

launch.json file launch.json 文件

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Extension",
        "type": "extensionHost",
        "request": "launch",
        "runtimeExecutable": "${execPath}",
        "args": [
            "--extensionDevelopmentPath=${workspaceFolder}"
        ],
        "outFiles": [
            "${workspaceFolder}/out/**/*.js"
        ],
        "preLaunchTask": "npm: watch"
    },
    {
        "name": "Extension Tests",
        "type": "extensionHost",
        "request": "launch",
        "runtimeExecutable": "${execPath}",
        "args": [
            "--extensionDevelopmentPath=${workspaceFolder}",
            "--extensionTestsPath=${workspaceFolder}/out/test"
        ],
        "outFiles": [
            "${workspaceFolder}/out/test/**/*.js"
        ],
        "preLaunchTask": "npm: watch"
    },

]

} }

Steps i followed is same as mentioned in VS code doc我遵循的步骤与 VS 代码文档中提到的相同

  1. npm install -g yo generator-code npm 安装-g yo 生成器代码
  2. yo code哟代码
  3. Launch VS Code,启动 VS 代码,
  4. choose File > Open Folder and pick the folder that you generated.选择“文件”>“打开文件夹”并选择您生成的文件夹。
  5. Press F5 or click on the Debug icon and click Start.按 F5 或单击“调试”图标,然后单击“开始”。

    For me step #5 is not working and not doing anything对我来说,第 5 步不起作用,也没有做任何事情

Your launch file doesn't look like the one generated by yo 2.0.2 .您的启动文件看起来不像yo 2.0.2生成的文件。 That one generates a launch file version 0.1.0 rather than 0.2.0 like yours.那个生成一个启动文件版本 0.1.0 而不是像你这样的 0.2.0。

Currently you should have yo 2.0.2 and vscode 1.24.0.目前你应该有 yo 2.0.2 和 vscode 1.24.0。 Please verify.请核实。

I created a typescript extension for vscode from the ground up and get this:我从头开始为 vscode 创建了一个打字稿扩展并得到这个:

{
  "version": "0.1.0",
  "configurations": [
    {
        "name": "Launch Extension",
        "type": "extensionHost",
        "request": "launch",
        "runtimeExecutable": "${execPath}",
        "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
        "stopOnEntry": false,
        "sourceMaps": true,
        "outDir": "${workspaceRoot}/out/src",
        "preLaunchTask": "npm"
    },
    {
        "name": "Launch Tests",
        "type": "extensionHost",
        "request": "launch",
        "runtimeExecutable": "${execPath}",
        "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
        "stopOnEntry": false,
        "sourceMaps": true,
        "outDir": "${workspaceRoot}/out/test",
        "preLaunchTask": "npm"
    }
  ]
}

For my case, I just reinstall the node, the same version, the problem solved.对于我的情况,我只是重新安装了节点,相同的版本,问题解决了。

sudo rm -rf /usr/local/lib/node_modules/npm
brew reinstall node

Reference: Error: Cannot find module '../lib/utils/unsupported.js' while using Ionic参考: 错误:在使用 Ionic 时找不到模块“../lib/utils/unsupported.js”

In my case it was the VSCode version, i updated to the latest and it worked就我而言,它是 VSCode 版本,我更新到最新版本并且它工作

I have the same issue in my VSCode vs code version 1.72我的 VSCode vs 代码版本 1.72 也有同样的问题

and in package.json it was the latest at generation time (1.74)在 package.json 中,它是生成时的最新版本 (1.74)

check the VSCode version in package.json检查 package.json 中的 VSCode 版本

"engines": {
   "vscode": "^1.52.0"
  },

use your version or less than your version使用您的版本或低于您的版本

EX:- my VSCode version is 1.72 and added 1.52例如:- 我的 VSCode 版本是 1.72 并添加了 1.52

In case you are trying to open it in a monorepo, open the extension in its own instance of vscode and then tap F5.如果您尝试在 monorepo 中打开它,请在它自己的 vscode 实例中打开扩展,然后点击 F5。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM