本文针对用code runner无法运行js和用debug无法调试js。先是code runner的解决方法:
file-preference-setting打开设置,搜索Edit in settings.json
在末尾加上:
"code-runner.executorMap": {
"javascript": "D:\\nodejs\\useless\\node.exe",
"python": "python",
"go": "go run",
"html": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
},
"code-runner.executorMapByGlob": {
"pom.xml": "cd $dir && mvn clean package",
"*.test.js": "tap",
"*.js": "node",
"*.ss":"scheme"
}
运行成功:
如果是debug调试js:
本文件夹是正在用vscode打开或者打开过的,都会默认加一个.vscode文件夹。
修改launch文件内容如下,注意,最后一行是你自己的node.exe路径,如果你没装nodejs,需要先装,“program”后面的文件名字是每次要修改的,调试哪个文件就是哪个名字。
"version": "0.2.0",//版本如果本来不是0.2勿修改
"configurations": [
{
"type": "node",
"request": "launch",
"name": "启动程序",
"program": "${workspaceFolder}/1.js",
"runtimeExecutable": "D:\\nodejs\\useless\\node.exe"
}
]
图中的name是自己定的,和调试时的选项名有关,要是定义多个configuration,那你想用哪个设置就选对应的name,比如你拿谷歌浏览器调试,那你就加一个关于谷歌浏览器调试的设置,比如想调试html,可以搜索“vscode 用谷歌 调试html文件”。
这样就可以调试了,不加断点情况下等同于run
另外,有的配置环境可能要在.vscode文件夹下加task和property啥的,但是目前用不着。
参考自多个网上资料,其中包括https://www.jianshu.com/p/f45a8ea57a45