【问题标题】:Error: ENOENT: no such file or directory, open 'D:\d%3A\VSCodeExt\fun\index.html'错误:ENOENT:没有这样的文件或目录,打开 'D:\d%3A\VSCodeExt\fun\index.html'
【发布时间】:2021-07-14 22:38:01
【问题描述】:

我确实看到了类似的问题,但没有实际答案。我的问题是它不断在路径上添加d%3A。我不知道它为什么这样做。我觉得如果它不这样做,我可以完成我的扩展。 是的,我正在使用教程进行操作,但我无法弄清楚路径情况。我知道还有其他问题,但他们的问题实际上是不同的。

我的扩展.js

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');
const fs = require('fs');
const path = require('path')

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed

/**
 * @param {vscode.ExtensionContext} context
 */
function activate(context) {

    // 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
    console.log('Congratulations, your extension "alsbp" is now active!');

    // 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
    let disposable = vscode.commands.registerCommand(
        'alsbp.createBoilerPlate', 
        function () {
            const htmlContent = `
            <!DOCTYPE html>
            <html lang="en">
            <head>
                <meta charset="UTF-8">
                <meta http-equiv="X-UA-Compatible" content="IE=edge">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <title>Your Title</title>
                <link rel="stylesheet" href="./app.css">
            </head>
            <body>
            <script src="./app.js"></script>
            </body>
            </html>
            `;
        
        const folderPath = vscode.workspace.workspaceFolders[0].uri.toString().split(":")[1];
            console.log(folderPath)
        fs.writeFile(path.join(folderPath, "index.html"), htmlContent, err =>{
            if(err){
                console.error(err);
                return vscode.window.showErrorMessage("Failed dude just failed")
            };
            vscode.window.showInformationMessage("Created boiler plate")
        }
        );
    });

    context.subscriptions.push(disposable);
}

// this method is called when your extension is deactivated
function deactivate() {}

module.exports = {
    activate,
    deactivate
}

package.json

{
    "name": "alsbp",
    "displayName": "AlsBoilerPlates",
    "description": "generate a html js and css file and have the emmet link app.js and css file",
    "version": "0.0.1",
    "engines": {
        "vscode": "^1.58.0"
    },
    "categories": [
        "Other"
    ],
    "activationEvents": [
        "onCommand:alsbp.createBoilerPlate"
    ],
    "main": "./extension.js",
    "contributes": {
        "commands": [
            {
                "command": "alsbp.createBoilerPlate",
                "title": "Create Al's Boiler Plates"
            }
        ]
    },
    "scripts": {
        "lint": "eslint .",
        "pretest": "npm run lint",
        "test": "node ./test/runTest.js"
    },
    "devDependencies": {
        "@types/vscode": "^1.58.0",
        "@types/glob": "^7.1.3",
        "@types/mocha": "^8.2.2",
        "@types/node": "14.x",
        "eslint": "^7.27.0",
        "glob": "^7.1.7",
        "mocha": "^8.4.0",
        "typescript": "^4.3.2",
        "vscode-test": "^1.5.2"
    }
}

【问题讨论】:

    标签: javascript visual-studio-code vscode-extensions


    【解决方案1】:

    %3A 是 ':'(冒号)字符的 URL 编码表示。我对编写 VS Code 扩展或发生这种情况的上下文知之甚少,但也许它可以帮助你更进一步:)

    【讨论】:

    • 我会调查一下,非常感谢您的回答
    • 你让我看得很清楚,我明白了:)
    【解决方案2】:

    我不得不看路径:

    我原来有这个

    const folderPath = vscode.workspace.workspaceFolders[0].uri.toString().split(":")[1];
    

    并改成这个

    const folderPath = vscode.workspace.workspaceFolders[0].uri['fsPath']
    

    由于映射等原因,我忘记了能够使用 []。

    【讨论】:

      猜你喜欢
      • 2020-09-14
      • 2021-04-09
      • 1970-01-01
      • 1970-01-01
      • 2019-04-01
      • 1970-01-01
      • 2018-07-06
      • 1970-01-01
      • 2019-01-26
      相关资源
      最近更新 更多