简体   繁体   中英

Difference between nodeJS and electron

I am trying to write my own home automation system in 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

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

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.

If you are using webpack for example, you can follow the directions here: https://webpack.js.org/configuration/node

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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