Skip to content Skip to sidebar Skip to footer

Sanity Check: Rhino Does Not Have A Require Function, Right?

I'm using rhino from the JVM with the jaxax.script interfaces. I'm trying to evaluate JavaScript that contains 'require' calls. This does not work because there is no definition of

Solution 1:

require is a CommonJS spec that node.js (and other frameworks, like RingoJS) use. The newest version of Rhino does support require, but the one that ships with the JVM does not.

To work around it, you could either use Rhino directly instead of the javax.script interface, or implement the CommonJS module system yourself. You might be able to drop in the newer Rhino version in place of the JVM's, but I have no idea if that would work or not.

You might need to use something like RingoJS though, since there are other CommonJS specs that are probably assumed to be there and aren't supported by Rhino natively. Of course, there would still be issues with libraries that depend on node.js-specific features.


Post a Comment for "Sanity Check: Rhino Does Not Have A Require Function, Right?"