Java8のNashornでrequireしたい
現在React.jsを使用してアプリケーションを作成しています。
ブラウザ側ではwebpackを使用してコンポーネントをrequireして使用しています。
React.jsのサーバサイドレンダリングを使用してレスポンスを返したいと考えているのですが、Nashornにはrequireが存在しないようなので、https://github.com/nodyn/jvm-npm を利用してrequireしようとしています。
しかし以下のようにreactをrequireすると
engine.eval("load('./dist/jsx/jvm-npm.js');");
engine.eval("var React = require('./node_modules/react/react');");
エラーが発生してしまいます。Nashornでrequireを使う方法はないのでしょうか。
javax.script.ScriptException: ReferenceError: "process" is not defined
in ./dist/jsx/jvm-npm.js at line number 106 at column number 11 at
jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:564)
at
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:548)
at
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:528)
at
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:524)
at
jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:194)
at
javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at net.jirox.radarscope.RadarScope.render(RadarScope.java:35) at
net.jirox.radarscope.RadarScopeTest.testRender(RadarScopeTest.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483) at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at
org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at
org.junit.runners.ParentRunner.run(ParentRunner.java:309) at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: ./dist/jsx/jvm-npm.js:106:11 ReferenceError: "process" is
not defined at
jdk.nashorn.internal.scripts.Script$jvm_npm._L21$Require(./dist/jsx/jvm-npm.js:106)
at jdk.nashorn.internal.scripts.Script$\^eval_.runScript(:1)
at
jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:498)
at
jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:206)
at
jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378)
at
jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:546)
... 29 more