【问题标题】:Vscode gives error when using function from import in extension在扩展中使用导入函数时,Vscode 出错
【发布时间】:2021-10-17 11:12:53
【问题描述】:

好吧,所以,这个标题真的不好。但基本上我遇到的问题是,在尝试制作我自己使用的插件版本时,我一直无法运行它。

使它停止工作的原因似乎是使用从另一个本地文件(在打字稿中)导入的函数。我已经尝试了我能想到的一切,例如,复制一个工作扩展并替换代码,更改编译器设置复制官方扩展示例 github。以及在异步和非异步之间更改功能。

我还尝试从源代码运行原始插件以测试它是否与我的环境有关。但这确实奏效了。太好了……我对可能的原因有 0 条线索(导入的函数除外)。

(因为我不知道是什么原因导致我真的不知道哪些部分会有所帮助,所以下面的所有内容都不确定必要的水平,我之前也几乎没有做过任何关于 typescript 或 vscode 扩展的事情)

错误信息

Activating extension 'Kycklingris.vscode-profiles' failed: The "original" argument must be of type function. Received undefined.

我的主扩展名 .ts 文件,它适用于 test 注释掉但不包含它,并且 test 完全为空。

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { GetProfiles, GetSettings, GetWorkspaceSettings, SetProfiles, SetWorkspaceSettings } from "./settings";
import { CreateProfile, ApplyProfile, EditProfile, DeleteProfile, PickProfile, test } from './utils';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
    // Use the console to output diagnostic information (console.log) and errors (console.error)
    // This line of code will only be executed once when your extension is activated
    
    // The command has been defined in the package.json file
    // Now provide the implementation of the command with registerCommand
    // The commandId parameter must match the command field in package.json

    context.subscriptions.push(
        vscode.commands.registerCommand("vscode-profiles.Apply", Apply),
        vscode.commands.registerCommand("vscode-profiles.Create", Create),
        vscode.commands.registerCommand("vscode-profiles.Edit", Edit),
        vscode.commands.registerCommand("vscode-profiles.Delete", Delete),
    );
}
export function deactivate() {}

async function Apply() {
    test();
    //let id = await PickProfile();
    //ApplyProfile(id);
}

async function Create() {
    //CreateProfile();
}

async function Edit() {
    //let id = await PickProfile();
    //EditProfile(id);
}

async function Delete() {
    //let id = await PickProfile();
    //DeleteProfile(id);
}

从我的 package.json 中,我已经安装了所有这些,但不是全局的

"devDependencies": {
        "@types/node": "^12.20.19",
        "@types/vscode": "^1.59.0",
        "@typescript-eslint/eslint-plugin": "^4.29.1",
        "@typescript-eslint/parser": "^4.29.1",
        "eslint": "^7.32.0",
        "typescript": "^4.5.0-dev.20210814"
    },
    "dependencies": {
        "sqlite": "^4.0.23",
        "sqlite3": "^5.0.2",
        "util": "^0.12.4",
        "vscode": "^1.1.37"
    }

aaaaa 和我的 tsconfig.json

{
    "compilerOptions": {
        "strict": true, /* enable all strict type-checking options */
        "alwaysStrict": false,
        "module": "commonjs",
        "target": "es2019",
        "outDir": "out",
        "noImplicitAny": true,
        "noImplicitReturns": true,
        "lib": [
            "es2019"
        ],
        "sourceMap": true,
        "strictNullChecks": true,
        "rootDir": "src",
        "noUnusedLocals": true /* Report errors on unused locals. */
    },
    "include": [
        "./src"
    ],
    "exclude": [
        "./test",
        "./node_modules",
        "./.vscode-test"
    ]
}

编辑: utils 文件中的重要内容

import * as vscode from "vscode";
import { GetProfiles, GetSettings, SetProfiles, SetWorkspaceSettings, GetProfile, SetProfile } from "./settings";
import { Profile, Extension } from "./types";
import { UpdateExtensions, GetAllExtensions } from "./extensionUtil";

export async function test() {
    
}

目录结构为:

node_modules/
out/
    extension.js
    extension.js.map
    ...
src/
    extension.ts
    extensionUtil.ts
    settings.ts
    types.ts
    utils.ts
.eslintrc.json
package-lock.json
package.json
tsconfig.json

【问题讨论】:

  • 你能用utils文件内容,文件夹结构更新问题吗?哪个扩展有 utilil 文件?
  • @Max 很抱歉花了一些时间,但我现在已经更新了

标签: typescript vscode-extensions


【解决方案1】:
const fs = require("fs");
const readDir = promisify(fs.readdirectory);

应该是

const fs = require("fs");
const readDir = promisify(fs.readdir);

我不知道为什么会这样的确切细节,因为这是我没有编写而是保留的代码的一部分。

【讨论】:

    猜你喜欢
    • 2018-02-25
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 2021-01-03
    • 1970-01-01
    相关资源
    最近更新 更多