上午原本想写程序,打开VSCode之后发现不能打开.ipynb文件了,报错信息如下:

Error loading webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..

The editor could not be opened due to an unexpected error: Could not initialize webview: Error: Could not register service worker: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state..

在网上查了一些解决方法,尝试过删除vscode缓存(~/Library/Application Support/Code/)、重新安装插件和重启VSCode,但都不起作用。经过不懈努力,终于在stack overflow上找到了适合我的解决方案,删除Service Worker文件夹之后重启VSCode,.ipynb文件就可以正常显示了!

There is another possible reason for OSX, that the files in the following paths are restricted by user permissions.

MAC: ~/Library/Application Support/Code/Service Worker

You can directly delete folders with restricted permissions.

After restarting VScode, he will generate it again.