Skip to content

ReactDOMServer 0.14.0 doesn't eval on Java 8 Nashorn JavaScript Engine #5311

@aantono

Description

@aantono

With the release of 0.14.0 and the modular split, the use of ReactDOMServer.renderToString(...) in the code instead of the original React.renderToString(...) results with an error in Nashorn, as it does not support any module system, so it is not possible to execute the suggested require('react-dom/server').

The code for testing was obtained from here and modified to use version 0.14.0 instead of 0.13.1 - https://github.com/sdeleuze/spring-react-isomorphic
This is being executed on the latest version of Java 8 - 1.8.0_66

Potentially related to #3037

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Failed to render script template] with root cause
jdk.nashorn.internal.runtime.ECMAException: ReferenceError: "ReactDOMServer" is not defined
    at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) ~[nashorn.jar:na]
    at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319) ~[nashorn.jar:na]
    at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291) ~[nashorn.jar:na]
    at jdk.nashorn.internal.objects.Global.__noSuchProperty__(Global.java:1432) ~[nashorn.jar:na]
    at jdk.nashorn.internal.scripts.Script$Recompilation$779$48AA$\^eval\_#1\!6653\^eval\_.process(<eval>#1:6653<eval>:25) ~[na:na]
    at jdk.nashorn.internal.scripts.Script$Recompilation$777$1754AA$\^eval\_.L:1$render(<eval>:1) ~[na:na]
    at jdk.nashorn.internal.scripts.Script$Recompilation$757$33AA$\^eval\_.render(<eval>:3) ~[na:na]
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:644) ~[nashorn.jar:na]
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228) ~[nashorn.jar:na]
    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) ~[nashorn.jar:na]
    at jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199) ~[nashorn.jar:na]
    at jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:383) ~[nashorn.jar:na]
    at jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190) ~[nashorn.jar:na]
    at org.springframework.web.servlet.view.script.ScriptTemplateView.renderMergedOutputModel(ScriptTemplateView.java:294) ~[spring-webmvc-4.2.0.RELEASE.jar:4.2.0.RELEASE]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions