简体   繁体   English

nodeJS和电子之间的区别

[英]Difference between nodeJS and electron

I am trying to write my own home automation system in javascript.我正在尝试用 javascript 编写我自己的家庭自动化系统。 The system should have a UI so that I can access some general controls for it.系统应该有一个用户界面,以便我可以访问它的一些常规控件。

Since it requires a UI, I thought "why not make it a fat electron app".由于它需要一个用户界面,我想“为什么不让它成为一个胖电子应用程序”。 So I am now trying out electron and svelte.所以我现在正在尝试电子和苗条。 But the issue I am running into is that it doesn't look like I am able to import my normal packages for controlling philips hue.但我遇到的问题是,我似乎无法导入用于控制飞利浦色调的普通包。

For example if I import philips-hue with例如,如果我导入philips-hue

import Hue from "philips-hue";

it immediately throws a ReferenceError: events is not defined and if I try using the package node-hue-api it throws the same error but references url instead of events它立即抛出一个ReferenceError: events is not defined如果我尝试使用包node-hue-api它会抛出相同的错误但引用url而不是events

This is quite confusing for me since I have used these packages many times before without issues when I am writing a normal node express server.这对我来说很困惑,因为我之前在编写普通节点快速服务器时已经多次使用这些包而没有出现问题。

So I am wondering why it won't work on electron and svelte, and if there is any "quick fix" solutions that solves this issue?所以我想知道为什么它在电子和苗条上不起作用,是否有任何“快速修复”解决方案可以解决这个问题?

You will need to polyfill the nodejs built-ins, as these do not exist in other environments such as electron.您需要对 nodejs 内置插件进行 polyfill,因为它们在其他环境(例如电子)中不存在。

If you are using webpack for example, you can follow the directions here: https://webpack.js.org/configuration/node例如,如果您正在使用 webpack,则可以按照此处的说明进行操作: https ://webpack.js.org/configuration/node

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM