How do I use ${workspaceRoot} for my Electron app in Visual Studio Code?

我们两清 提交于 2019-12-10 10:23:00

问题


I have an Electron app that I was able to debug in Visual Studio Code. After I upgraded to version 0.10.8 it will no longer run.
I am getting the error message below in my launch.json file:

Relative paths will no longer be automatically converted to absolute ones. Consider using ${workspaceRoot} as a prefix.

Absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.

Here is my launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "My First Electron App",
            "type": "node",
            "request": "launch",
            "program": "$(workspaceRoot}/app/main.js", //ERROR
            "stopOnEntry": false,
            "args": [],
            "cwd": "$(workspaceRoot}",
            "runtimeExecutable": "$(workspaceRoot}/node_modules/electron-prebuilt/dist/electron.app/Contents/MacOS/Electron", //ERROR
            "runtimeArgs": [
                "--nolazy"
            ],
            "env": {
                "NODE_ENV": "development"
            },
            "externalConsole": false,
            "sourceMaps": false,
            "outDir": null
        },
        {
            "name": "Attach",
            "type": "node",
            "request": "attach",
            "port": 5858
        }
    ]
}

I am getting the green squiggly line mentioned for the two lines with //ERROR at the end.

I saw this article, but honestly was familiar with VS Code enough to understand how this should be implemented: https://code.visualstudio.com/Docs/editor/tasks#_variable-substitution

UPDATE
I replaced the value for "cwd" with "${workspaceRoot}" as recommended by Isidor. The green squiggly line went away.

I updated the error message that I am still seeing on the other two lines.

When I hit F5 I get this error message:

request 'launch': runtime executable '/private/var/git/electron-vs-code/$(workspaceRoot}/node_modules/electron-prebuilt/dist/electron.app/Contents/MacOS/Electron' does not exist


回答1:


There is a typo in your json. Change the parenthesis after the $ in $(workspaceRoot} to a curly brace. This should at least fix the warning.




回答2:


Even though you are getting the relative path warning VSCode still automatically converts relative to absolute paths in 0.10.8. To get rid of the warnings for "cwd", instead of "." please put "${workspaceRoot}".

What happens when you run try to debug your electron app, do you see some other error, since the relative to absolute can not be the true cause of this. If you command palette / open developper tools -> do you see some error in the console?



来源:https://stackoverflow.com/questions/35305358/how-do-i-use-workspaceroot-for-my-electron-app-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!