LiquidPlayer / LiquidCore

Node.js virtual machine for Android and iOS
MIT License
1.01k stars 127 forks source link

NodeRed in LiquidCore #167

Open alyberty opened 4 years ago

alyberty commented 4 years ago

Hi, I was wondering what would be the best way to run NodeRed on LiquidCore (on iOS). NodeRed is quite a large project, with a lot of dependencies.

I tried it with multiple different settings.

I ran into different problems, which I could not fully remove.

The bundling with metro posed some challanges, but I adapted the require code as good as I could. (requires in try catch, protected terms etc.) The programm still crashed. Then I tried it with ncc, so the required code should be all in one file. I know that the combination of ncc and then metro is not ideal, but from my point of view, it should still work. I couldn't test, if the bundled file would still run, because of the missing LiquidCore module. I again encountered the same problem (but less) with metro, which I fixed again. Out of ideas, I also tried to bundle it with browserify, but also no luck. I also checked for native modules. NodeRed depends optionally on bcrypt, but I made sure it was not installed.

Can you guide me in the right direction to make this work?

I was wondering if LCProcess would be the right way to go here. I"m not sure if this would also allow me to skip the whole metro-bundling step.

I'd appreciate your input on that. Thank you for your time and effort you put into this project, regardless!

Here is also some output of the crash[es]: Maybe someone has more insight into what it could mean.

npm only with entrypoint:

2020-04-24 06:50:08.774738-0700 redios[45712:1061105] MicroService User-Agent : LiquidCore/0.7.7 (iOS; API=13.4.1)
2020-04-24 06:50:09.010414-0700 redios[45712:1061105] There is an unhandled exception!
2020-04-24 06:50:09.010678-0700 redios[45712:1061105] Error: Error: Cannot resolve module
2020-04-24 06:50:09.011027-0700 redios[45712:1061105] Stack: :684
<Source line not available>

red.bundle.js:684:18
loadModuleImplementation@red.bundle.js:290:14
global code@red.bundle.js:686:4
[native code]
instantiate@[native code]:2:274

global code
[native code]
global code@[eval]:1:26
[native code]
instantiate@[native code]:2:274
[eval]-wrapper:6:38
internal/modules/cjs/loader.js:701:34
evalScript@internal/bootstrap/node.js:589:35
startup@internal/bootstrap/node.js:265:19
bootstrapNodeJSCore@internal/bootstrap/node.js:622:10
anon@[native code]:2:16
2020-04-24 06:50:09.013797-0700 redios[45712:1061105] There is an unhandled exception!
2020-04-24 06:50:09.013963-0700 redios[45712:1061105] Error: null
2020-04-24 06:50:09.029095-0700 redios[45712:1061105] Stack: undefined
:496
<Source line not available>

[native code]
emit@events.js:189:18
internal/bootstrap/node.js:496:31
anon@[native code]:2:16

packed with ncc

Error: TypeError: undefined is not an object (evaluating 'stack[0].toString')
2020-04-24 07:02:29.872418-0700 redios[48075:1075255] Stack: index.bundle.js:27460
<Source line not available>

callSiteToString@index.bundle.js:27460:22
get@index.bundle.js:27468:25
index.bundle.js:40191:52
__webpack_require__@index.bundle.js:701:29
index.bundle.js:4845:40
__webpack_require__@index.bundle.js:701:29
index.bundle.js:25048:41
__webpack_require__@index.bundle.js:701:29
index.bundle.js:9248:41
__webpack_require__@index.bundle.js:701:29
index.bundle.js:49831:38
__webpack_require__@index.bundle.js:701:29
index.bundle.js:715:4
loadModuleImplementation@index.bundle.js:290:14
global code@index.bundle.js:83032:4
[native code]
instantiate@[native code]:2:274

global code
[native code]
global code@[eval]:1:26
[native code]
instantiate@[native code]:2:274
[eval]-wrapper:6:38
internal/modules/cjs/loader.js:701:34
evalScript@internal/bootstrap/node.js:589:35
startup@internal/bootstrap/node.js:265:19
bootstrapNodeJSCore@internal/bootstrap/node.js:622:10
anon@[native code]:2:16
2020-04-24 07:02:29.876629-0700 redios[48075:1075255] There is an unhandled exception!
2020-04-24 07:02:29.877097-0700 redios[48075:1075255] Error: null
2020-04-24 07:02:29.890453-0700 redios[48075:1075255] Stack: undefined
:496
<Source line not available>

[native code]
emit@events.js:189:18
internal/bootstrap/node.js:496:31
anon@[native code]:2:16
ericwlange commented 4 years ago

I have encountered the callSiteToString problem before. It is because JavaScriptCore does not include all the fancy Error methods that V8 supports and some node modules depend on. I fixed this, coincidentally in 0.7.9, by improving the error polyfill for iOS. You can see if this gets you further.

alyberty commented 3 years ago

Thnaks for your input! I think this fixed the specific problem.

But now I am stuck with another Error:

Error: TypeError: _$$_REQUIRE.resolve is not a function. 
  (In '_$$_REQUIRE.resolve("@node-red/nodes")', '_$$_REQUIRE.resolve' is undefined)

The relevant code line is:

userSettings.coreNodesDir = path.dirname(require.resolve("@node-red/nodes"))

I am also not sure if this is a problem from with LiquidCore or just (what I actually suspect) an incompatibility from metro with node-red. Node-red also tries to iterate over directories within a loaded module, which I doubt metro can handle.

Is it possible to run the LCMicroService without a bundle, but with the folder structure intact?