VS Code无法运行/调试代码,抛出“Cannot convert undefined or null to object”错误
VS Code调试/运行代码报错:Cannot convert undefined or null to object
问题详情
运行Python或JavaScript代码时,VS Code均抛出错误:"Cannot convert undefined or null to object"。已尝试清除用户/程序设置、重新安装VS Code,问题未解决。
当前launch.json配置:
// Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "justMyCode": true } ]
问题截图:

解决步骤
- 检查终端环境变量:打开集成终端,执行
echo $PATH(Linux/macOS)或echo %PATH%(Windows),确认Python、Node.js的可执行路径存在且有效。路径缺失的话,手动添加对应语言安装目录到系统环境变量,重启VS Code。 - 排查扩展冲突:按
Ctrl+Shift+X打开扩展面板,点击右上角三点选择「禁用所有已安装扩展」,重启后测试代码运行。若问题消失,逐个启用扩展找出冲突项。 - 重置终端配置:打开VS Code设置,搜索
terminal.integrated.defaultProfile,切换为系统默认终端(如Windows的命令提示符、macOS的Terminal),重启后重试。 - 重置工作区配置:备份项目根目录下的
.vscode文件夹后删除,重新生成launch.json和settings.json。 - 修复VS Code安装:切换至内部人员版本,或下载最新稳定版覆盖安装,确保安装包完整。
内容的提问来源于stack exchange,提问作者MaxMusic
相关产品推荐
相关产品推荐

