当我尝试在VSC中运行调试器时,我不断收到此错误消息。谁能帮忙吗? 这是屏幕截图:
我是编程和课程学习的新手,请尽可能保持基本解释。
这是JS文件的代码。我已经使用Yo Code和NPM生成了基本的Visual Studio代码扩展。
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import { commands, window } from 'vscode';
// 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 "content-helper" 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 = commands.registerCommand('extension.helloWorld', function () {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
window.showInformationMessage('Hello World!');
});
context.subscriptions.push(disposable);
}
const _activate = activate;
export { _activate as activate };
// this method is called when your extension is deactivated
function deactivate() {}
export default {
activate,
deactivate
}
答案 0 :(得分:2)
VS代码扩展在不固有支持模块的节点环境中运行(因此,没有import
和export
)。
yo code
仅在创建TypeScript扩展名时使用import
。对于js扩展名,yo code
改用require
:
const vscode = require('vscode');
要在VS Code扩展中使用import
,必须使用TypeScript或webpack之类的工具将代码编译为目标Node。