完整性检查:Rhino没有require函数,对吧? [英] Sanity check: Rhino does not have a require function, right?

查看:204
本文介绍了完整性检查:Rhino没有require函数,对吧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JVM中的rhino和jaxax.script接口。我正在尝试评估包含require调用的JavaScript。这不起作用,因为没有'require'的定义。只需要一个v8的东西?或者只是一个node.js的东西?在JVM上有解决方法吗?我能想到的选项是

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 'require'. Is require just a v8 thing? Or maybe just a node.js thing? Are there ways around this on the JVM? Options I can think of are


  • 通过手动包含所需代码重写js文件

  • 调用out到一个单独的node.js进程

(我不一定推荐这些方法。)

(I'm not necessarily recommending the approaches.)

推荐答案

require CommonJS 规范node.js(以及其他框架,如 RingoJS )使用。最新版本的Rhino支持 require ,但JVM附带的版本不支持。

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.

工作在它周围,你可以直接使用Rhino而不是 javax.script 接口,或者自己实现CommonJS模块系统。您可能可以使用较新的Rhino版本代替JVM,但我不知道这是否可行。

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.

您可能需要使用某些东西比如RingoJS,因为还有其他的CommonJS规范可能被认为存在并且本身并不支持Rhino。当然,依赖于node.js特定功能的库仍然存在问题。

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.

这篇关于完整性检查:Rhino没有require函数,对吧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆