Solr DataImportHandler using ScriptTransformer: JavaScript functionality severely limited

I’m using a simple ScriptTransformer <script> in my db-data-config.xml DataImportHandler. I’d like to decode htmlentities and found I should be using he module. Downloaded the zip and extracted in conflib. This is part of my script:

var he = require('./lib/he-master/he.js');
function removeSpecialCharacters(text) {
     if (typeof text !== 'string') {
          return text;
     }
     return he.decode(text);
}

But I get the error:

javax.script.ScriptException: ReferenceError: "require" is not defined in <eval>

Why does nothing work out of the box (like JS require function) and how do I solve this?

It’s cheaper to pay than use open source because nothing works out of the box. It takes ages of troubleshooting ($) before something with a little bit of an advanced functionality works.

also tried

eval(readFile('./lib/he-master/he.js');

But it’s the same story: nothing is included out of the box with Solr:

javax.script.ScriptException: ReferenceError: "readFile" is not defined in <eval>