使用带有Node.js工具的Visual Studio(而非VSCode)创建Electron应用 [英] Creating an Electron app using Visual Studio (not VSCode) w/ Node.js tools

查看:268
本文介绍了使用带有Node.js工具的Visual Studio(而非VSCode)创建Electron应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Visual Studio(而不是VSCode)创建一个简单的Electron应用程序.我是通过Visual Studio(v1.1)扩展的Node.js工具这样做的.我正在使用基本的快速启动应用程序,如果通过npm start启动,则可以正常运行,但是如果通过Visual Studio启动,则在启动时会出现以下错误:

I'm trying to use Visual Studio (not VSCode) to create a simple Electron app. I'm doing so via the Node.js tools for Visual Studio (v1.1) extension. I'm using the basic quick start app which works fine if I launch via npm start, but if I launch via Visual Studio, I get the following error on start up:

'在第一行找不到模块'electron':
const electron = require('electron');

'Cannot find module 'electron' on the first line:
const electron = require('electron');

我可以告诉Visual Studio在启动它的node.js调试器之前先启动Electron应用程序吗?还有其他人可以完全使用此设置吗?

Can I tell Visual Studio to launch the Electron app first before starting it's node.js debugger? Has anyone else gotten this set up to work at all?

推荐答案

这是可能的.尝试执行以下操作:

This is possible. Try doing what's below:

  • 在Visual Studio中创建一个空白的Node.js JavaScript控制台应用程序.你需要一个 我认为安装了最新版本的节点:我有12.15.0.我正在使用VS 2019社区.
  • 向创建的package.json中添加一个依赖项部分,并 参考电子.我引用了8.0.0,如下所示:

  • Create a blank Node.js JavaScript console app in Visual Studio. You need a recent version of node installed I think: I have 12.15.0. I'm using VS 2019 Community.
  • Add a dependencies section to the package.json that's created and reference electron. I referenced 8.0.0 as below:

"dependencies": { "electron": "8.0.0" },

这一切都很好,但是它的用处取决于您真正希望Visual Studio为您做些什么.尽管您可以照常使用Chrome开发人员工具调试渲染器线程,但它只会在主线程上中断.我发现节点工具应用程序有一些限制.也许其他项目类型之一会更好.

This is all well and good, but how useful it is depends on what you really want Visual Studio to do for you. It will only break on the main thread, although you can debug the renderer threads using the Chrome dev tools as usual. I find the node tools apps a little limiting. Maybe one of the other project types would be better.

此答案已于2020年2月更新,以前的答案已删除.请注意,在npm世界中,事情确实会随着时间的流逝而破裂:如果事情对您不利,请发表评论.

This answer was updated February 2020, and previous answers removed. Note that as usual in npm world things do tend to break over time: please make a comment if things aren't working for you.

这篇关于使用带有Node.js工具的Visual Studio(而非VSCode)创建Electron应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆