【vscode】调试cocos creator (Js 无法命中断点问题解决)
We couldn’t find a corresponding source location, but found some other files with the same name:You may need to adjust the webRoot in your launch.json if you’re building from a subfolder, or tweak you
一、安装插件
Debugger for Chrome已弃用
- 安装 JavaScript Debugger (Nightly) 插件替代,其他步骤完全一样。
二、通过cocos creator打开任意js脚本,按F5,选择Web 应用(Chrome)
自动生成 launch.json如下
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
三、修改url端口成7456
launch.json如下
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:7456",
"webRoot": "${workspaceFolder}"
}
]
}
四、按F5进行调试
正常情况下应该可以调试了。
其他错误
1.找不到浏览器
Unable to launch browser: “Unable to find an installation of the browser on your system. Try installing it, or providing an absolute path to the browser in the “runtimeExecutable” in your launch.json.”
查看谷歌浏览器安装路径,修改launch.json如下
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:7456",
"runtimeExecutable": "C:/Users/Administrator/AppData/Local/MyChrome/Chrome/Application/chrone.exe",
"webRoot": "${workspaceFolder}"
}
]
}
runtimeExecutable 就是谷歌浏览器所在路径。
2. 断点异常(打不上断点)
This breakpoint was initially set in:
E:\Project\xxx\assets\scripts\AppStart.js line 22 column 1
❓ We couldn’t find a corresponding source location, but found some other files with the same name:
E:\Project\xxx\assets\scripts\AppStart.js
e:\Project\xxx\assets\scripts\AppStart.js
You may need to adjust the webRoot in your launch.json if you’re building from a subfolder, or tweak your sourceMapPathOverrides.
这类问题,找了很久的解决方案,后面稀里糊涂解决了我个人的问题。
修改launch.json如下: (仅供参考)
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:7456",
"runtimeExecutable": "C:/Users/Administrator/AppData/Local/MyChrome/Chrome/Application/chrone.exe",
"webRoot": "${workspaceFolder}/scripts"
}
]
}
这里是一个专注于游戏开发的社区,我们致力于为广大游戏爱好者提供一个良好的学习和交流平台。我们的专区包含了各大流行引擎的技术博文,涵盖了从入门到进阶的各个阶段,无论你是初学者还是资深开发者,都能在这里找到适合自己的内容。除此之外,我们还会不定期举办游戏开发相关的活动,让大家更好地交流互动。加入我们,一起探索游戏开发的奥秘吧!
更多推荐
所有评论(0)