javascript VS代码扩展开发过程中出现“未找到命令”错误(由于需要axios行)

chhkpiq4  于 2022-12-25  发布在  Java
关注(0)|答案(2)|浏览(100)

我尝试开发一个VS代码扩展遵循简单的youtube教程。扩展工作良好,对话框出现在th开始,但当我添加axios包和它的代码,它给命令未找到错误在开发窗口。
图片:Error msg command not found in VSC extension
下面是extension.js(您可以忽略其实现):

const vscode = require("vscode")
const axios = require("axios")
const xmlParser = require("fast-xml-parser")

/**
 * @param {vscode.ExtensionContext} context
 */
async function activate(context) {
  const res = await axios.get("https://blog.webdevsimplified.com/rss.xml")
  const articles = xmlParser.parse(res.data).rss.channel.item.map(article => {
    return {
      label: article.title,
      detail: article.description,
      link: article.link,
    }
  })

  let disposable = vscode.commands.registerCommand(
    "wds-search-blog-example.searchWdsBlogExample",
    async function () {
      const article = await vscode.window.showQuickPick(articles, {
        matchOnDetail: true,
      })

      if (article == null) return

      vscode.env.openExternal(article.link)
    }
  )

  context.subscriptions.push(disposable)
}
exports.activate = activate

function deactivate() {}

module.exports = {
  activate,
  deactivate,
}

package.json

{
    "name": "wds-blog-search",
    "displayName": "WDS Blog Search",
    "description": "Search Web Dev Simplified's Blog For Articles",
    "version": "1.0.1",
    "publisher": "WebDevSimplified",
    "repository": {
        "url": "https://github.com/WebDevSimplified/vscode-extension-blog-searcher"
    },
    "icon": "logo.png",
    "engines": {
        "vscode": "^1.52.0"
    },
    "categories": [
        "Other"
    ],
    "activationEvents": [
        "onCommand:wds-blog-search.searchWdsBlog"
    ],
    "main": "./extension.js",
    "contributes": {
        "commands": [
            {
                "command": "wds-blog-search.searchWdsBlog",
                "title": "Search WDS Blog"
            }
        ]
    },
    "scripts": {
        "lint": "eslint .",
        "pretest": "npm run lint",
        "test": "node ./test/runTest.js"
    },
    "devDependencies": {
        "@types/vscode": "^1.52.0",
        "@types/glob": "^7.1.3",
        "@types/mocha": "^8.0.4",
        "@types/node": "^12.11.7",
        "eslint": "^7.15.0",
        "glob": "^7.1.6",
        "mocha": "^8.1.3",
        "typescript": "^4.1.2",
        "vscode-test": "^1.4.1"
    },
    "dependencies": {
        "axios": "^0.21.1",
        "fast-xml-parser": "^3.17.6"
    }
}

参考:https://github.com/WebDevSimplified/vscode-extension-blog-searcher
据我所知没有语法错误。在另一个系统上试过,但仍然得到同样的问题。不能理解什么是错误的。请帮助。

mw3dktmi

mw3dktmi1#

需要在require上调用.default,如下所示:

const axios = require("axios").default;

***但我也不得不彻底放弃这个项目,重新开始。***因为即使删除了我所有的修改,并将hello世界恢复到原来的状态,它仍然是坏的。无论axios做了什么,它都做得很好。

所以,有两件事。
1.放弃这个项目,重新开始
1.将.default附加到require()
我不知道为什么youtube用户可以不调用.default,也许axios最近发生了什么变化?

ego6inou

ego6inou2#

我跟着同样的视频,得到了一个非常相似的错误:

Command 'Hello World' resulted in an error (command 'wds-search-blog-example.helloWorld' not found)
Activating extension 'undefined_publisher.wds-search-blog-example' failed: connect EACCES :443.

在检查来自try...catch的错误消息( Package 在try...catch中)后,我收到了以下信息:
一个二个一个一个
我可以通过在查询中添加一个带有编码的头来解决这个问题(来自here的想法):

const axios = reqiure('axios');
//...
async function activate(context) {
  const res = await axios.get(
    "https://blog.webdevsimplified.com/rss.xml",
    { headers: { "Accept-Encoding": "gzip,deflate,compress" } }
  )
  //...
}

我使用axios 1.2.1。

相关问题