如何从Visual Studio Code运行我的电子项目

时间:2022-10-30 16:33:45

I'm new in JavaScript. And I want to create an application with electron framework in Visual Studio Code. I'm working on debian. The electron module is installed locally, and I can execute my app from command line. But unfortunately I can't set up the VS code to run it. I tried this guide, but it didn't help me. I have the following launch.json:

我是JavaScript的新手。我想在Visual Studio Code中创建一个带有电子框架的应用程序。我正在研究debian。电子模块安装在本地,我可以从命令行执行我的应用程序。但不幸的是我无法设置VS代码来运行它。我试过这个指南,但它没有帮助我。我有以下launch.json:

{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
    {
        // Name of configuration; appears in the launch configuration drop down menu.
        "name": "Launch main.js",
        // Type of configuration. Possible values: "node", "mono".
        "type": "node",
        // Workspace relative or absolute path to the program.
        "program": "electron/main.js",
        // Automatically stop program after launch.
        "stopOnEntry": false,
        // Command line arguments passed to the program.
        "args": [],
        // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
        "cwd": ".",
        // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
        "runtimeExecutable": "node_modules/electron-prebuilt/dist/electron",
        // Optional arguments passed to the runtime executable.
        "runtimeArgs": [],
        // Environment variables passed to the program.
        "env": {
            "NODE_ENV": "development"
        },
        // Use JavaScript source maps (if they exist).
        "sourceMaps": false,
        // If JavaScript source maps are enabled, the generated code is expected in this directory.
        "outDir": null
    },
    {
        "name": "Attach",
        "type": "node",
        // TCP/IP address. Default is "localhost".
        "address": "localhost",
        // Port to attach to.
        "port": 5858,
        "sourceMaps": false
    }
]

}

If I try to execute, but a blank terminal comes up and the VS code says that "OpenDebug process has terminated unexpectedly".

如果我尝试执行,但是出现一个空白终端并且VS代码说“OpenDebug进程意外终止”。

Update:

Meanwhile Visual Studio Code has been improved a lot. Here is a good description, how should be VS code set up for electron: http://electron.rocks/debugging-electron-in-vs-code/

同时Visual Studio Code也得到了很大的改进。这是一个很好的描述,如何为电子设置VS代码:http://electron.rocks/debugging-electron-in-vs-code/

1 个解决方案

#1


0  

When you run electron like that you need to pass an argument to the directory containing your app. There may be some other issue but I think you need to set the program to be the local directory instead of a file:

当您像这样运行电子时,您需要将参数传递给包含您的应用程序的目录。可能还有其他一些问题,但我认为您需要将程序设置为本地目录而不是文件:

"program": ".",

Code should then invoke the electron script and pass "." as the first argument now. It could be that the debug options aren't supported by electron also, try unsetting the port and address properties.

然后代码应该调用电子脚本并传递“。”作为现在的第一个论点。可能是电子也不支持调试选项,尝试取消设置端口和地址属性。

#1


0  

When you run electron like that you need to pass an argument to the directory containing your app. There may be some other issue but I think you need to set the program to be the local directory instead of a file:

当您像这样运行电子时,您需要将参数传递给包含您的应用程序的目录。可能还有其他一些问题,但我认为您需要将程序设置为本地目录而不是文件:

"program": ".",

Code should then invoke the electron script and pass "." as the first argument now. It could be that the debug options aren't supported by electron also, try unsetting the port and address properties.

然后代码应该调用电子脚本并传递“。”作为现在的第一个论点。可能是电子也不支持调试选项,尝试取消设置端口和地址属性。