开发VS Code扩展调试时遇「无视图数据提供者注册」错误求助
调试VS Code扩展时遇到「There is no data provider registered that can provide view data」错误
调试VS Code扩展时弹出如下错误:Error: "There is no data provider registered that can provide view data"

以下是我的extension.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'); // 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 getWebviewContent() { return `<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Video Player</title> </head> <body> <h1>Video Player</h1> <video width="640" height="360" controls> <source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4"> Your browser does not support the video tag. </video> </body> </html>`; } 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 "YourApp" is now active!'); let disposable = vscode.commands.registerCommand('extension.openVideo', function () { // Create and show a new webview const panel = vscode.window.createWebviewPanel( 'videoView', // Identifies the type of the webview. Used internally 'Video Player', // Title of the panel displayed to the user vscode.ViewColumn.One, // Editor column to show the new webview panel in. { enableScripts: true, // Enable JavaScript in the webview retainContextWhenHidden: true // Keep the webview's state even when it's hidden } ); // Set the HTML content for the webview panel.webview.html = getWebviewContent(); }); context.subscriptions.push(disposable); } // This method is called when your extension is deactivated function deactivate() {} module.exports = { activate, deactivate }
以下是我的package.json代码:
{ "name": "financenews", "displayName": "FinanceNews", "description": "", "version": "0.0.1", "engines": { "vscode": "^1.98.0" }, "categories": [ "Other" ], "activationEvents": [ "onView:videoView", "onCommand:extension.openVideo" ], "main": "./extension.js", "contributes": { "commands": [{ "command": "financenews.helloWorld", "title": "Hello World" }, { "command": "extension.openVideo", "title": "Open Video" }], "viewsContainers": { "activitybar": [ { "id": "videoSidebar", "title": "Video Sidebar", "icon": "media/mario.svg" } ] }, "views": { "videoSidebar": [ { "id": "videoView", "name": "Video Player" } ] } }, "scripts": { "lint": "eslint .", "pretest": "npm run lint", "test": "vscode-test" }, "devDependencies": { "@types/vscode": "^1.98.0", "@types/mocha": "^10.0.10", "@types/node": "20.x", "eslint": "^9.21.0", "@vscode/test-cli": "^0.0.10", "@vscode/test-electron": "^2.4.1" } }
已尝试以下方案,但问题仍未解决:
- 使用'explorer'替代'videoSidebar'
- 尝试创建VideoWebView类并将
getWebView()方法置于类内部 - 尝试从本地目录加载视频,而非使用
https://www.w3schools.com/html/mov_bbb.mp4作为源地址
内容的提问来源于stack exchange,提问作者Anubhav Pandey
相关产品推荐
相关产品推荐

