-
Notifications
You must be signed in to change notification settings - Fork 47.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React doesn't eval on Java 8 Nashorn JavaScript Engine #3037
Comments
The root of this issue is in the build tool: browserify's dependency browser-pack's dependency umd. In template.js it only checks for window, global, or self. You can send a PR there to fall back to For now, I'd recommend using |
Thanks for the hint. I've filed another issue. |
FYI: The issue is fixed in UMD. In the meanwhile I've found another incompatibility between React and Nashorn: There's no var global = this;
var console = {};
console.debug = print;
console.warn = print;
console.log = print; Dunno if this fixes all possible issues but that's what I found out so far. |
In the docs we do say that we require a console polyfill for browsers(/engines) that don't support it: http://facebook.github.io/react/docs/working-with-the-browser.html#browser-support-and-polyfills Doesn't sound like there's anything else we need to do here so I'm closing this. |
Thanks for pointing that out. |
Also, don't forget |
The root of this issue is fixed in this pull request: Suggested workarounds are just dodging the real problem. |
Nashorn is the new JavaScript Engine shipped with Java 8. Nashorn compiles JavaScript to Java Bytecode, so it runs natively on the JVM.
Unfortunately React doesn't evaluate properly on Nashorn due to the fact that Nashorn doesn't support any kind of module system like AMD out of the box.
This code creates a new nashorn engine and evaluates React on the JVM:
Running the above code results in the following error:
Simple workaround is to create a variable
window
referencing the the global contextthis
:BTW: Here's a fully working isomorphic java example of your CommentBox tutorial:
https://github.com/winterbe/spring-react-example
The CommentBox is initially rendered on the server with Nashorn.
The text was updated successfully, but these errors were encountered: