JS Scripting - Browserify

I was wonding if anyone has attempted/had luck/or know if something like Browserify would allow use of normal node imports or packages using them?

Given that the Graalvm is in the vanilla JS mode with the Commonjs require enabled vs the Nodejs vm. (not looking to discuss that choice or restrictions given not looked into the code much on either side)

Would there be gotchas that are known with this?

I’m definitely not going to have a full answer here but given Browserify’s stated purpose is

Use a node-style require() to organize your browser code and load modules installed by npm.

and GraalVM:

  1. already supports require() and loading modules installed by npm
  2. is only used on the server side for rules

It’s not clear what you are trying to achieve. Is there something else Browserify does or something I’m missing?

It supports require which is not really a node thing, but is used in nodejs projects. That said a simple example that does not work in the plugin

const path = require('path')
// or 
const fs = require('fs')

I picked two common nodejs modules (built-in) but same is true for any.

NPM can hold packages that are node-specific or just JS. Example the tools package you publish. The latter doesn’t rely on any nodejs internal packages.

So…

The thought was if this solution did work then you could leverage the tons of functions/classes in the nodejs internal library but then be compiled/transpiled to vanilla JS that can be commonjs required. Another example of where it would be helpful is with npm packages that rely on nodejs internals that provide the functionality you need. (Why re-invent the wheel if you can build the car instead)

The last reason would be is that the tool does support ESM and would be able to transpile that to commonjs and thus usable in the limitations we have.

I do understand there will be no ways around threading related issues because of the way graalvm ↔ Java operate with some objects.

I suspect the best way to find your answers will be to try it out and see.

There might be other options available to make this possible as well.

I don’t think there was a technical reason not to make the nodejs internal library available so much as the original devs of the add-on/helper library never needed/wanted to do it so that path was never explored. Though I could be wrong on that.

I think it would be worth opening a feature request issue (I’d start on the openhab-js repo) to explore options. But definitely also give Browserify a try and see if it’ll work. That might reveal some technical limitation or prove that it doesn’t cause problems which would be informative as well.

I’m all for opening an issue Wanted to see if anyone had tried or had more info. I couldn’t find much on the community but haven’t searched deeply through GH yet.

I am definitely gonna try unless someone was like been there tried that don’t waste your time.