Skip to content
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

SystemJS on Nashorm: TypeError: No environment baseURI #1113

Closed
manekinekko opened this issue Feb 21, 2016 · 5 comments
Closed

SystemJS on Nashorm: TypeError: No environment baseURI #1113

manekinekko opened this issue Feb 21, 2016 · 5 comments

Comments

@manekinekko
Copy link

(see also #1112)

Hi,
I am having some trouble getting systemjs loading on the Java 8 Nashron engine.
Here is my setup:

  • Java 8: 1.8.0_31
  • Spring boot: 1.3.0.RELEASE
  • SystemJS: 0.19.22

Here are the steps to reproduce this issue:

  1. Load system.js in Nashorn:
@Bean
public ScriptTemplateConfigurer universalConfigurer() {
    ScriptTemplateConfigurer configurer = new ScriptTemplateConfigurer();
    configurer.setEngineName("nashorn");
    configurer.setScripts(
          "static/node_modules/systemjs/dist/system.js"
           // ...
    );
    configurer.setRenderFunction("render");
    configurer.setSharedEngine(false);
    return configurer;
}
  1. Build and run. Nashorn should complain about No environment baseURI (Sorry for this long trace):
jdk.nashorn.internal.runtime.ECMAException: TypeError: No environment baseURI
    at jdk.nashorn.internal.objects.NativeError.initException(NativeError.java:138) ~[nashorn.jar:na]
    at jdk.nashorn.internal.objects.NativeTypeError.<init>(NativeTypeError.java:73) ~[nashorn.jar:na]
    at jdk.nashorn.internal.objects.NativeTypeError.<init>(NativeTypeError.java:77) ~[nashorn.jar:na]
    at jdk.nashorn.internal.objects.NativeTypeError.constructor(NativeTypeError.java:98) ~[nashorn.jar:na]
    at jdk.nashorn.internal.scripts.Script$\^eval\_.L:4$e$L:4(<eval>:4) ~[na:na]
    at jdk.nashorn.internal.scripts.Script$\^eval\_.L:4$e(<eval>:4) ~[na:na]
    at jdk.nashorn.internal.scripts.Script$\^eval\_.L:4(<eval>:5) ~[na:na]
    at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(<eval>:4) ~[na:na]
    at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:535) ~[nashorn.jar:na]
    at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:209) ~[nashorn.jar:na]
    at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378) ~[nashorn.jar:na]
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:568) ~[nashorn.jar:na]
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:525) ~[nashorn.jar:na]
    at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:521) ~[nashorn.jar:na]
    at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:187) ~[nashorn.jar:na]
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249) ~[na:1.8.0_31]
    at org.springframework.web.servlet.view.script.ScriptTemplateView.loadScripts(ScriptTemplateView.java:289) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.view.script.ScriptTemplateView.createEngineFromName(ScriptTemplateView.java:277) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.view.script.ScriptTemplateView.getEngine(ScriptTemplateView.java:260) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.view.script.ScriptTemplateView.renderMergedOutputModel(ScriptTemplateView.java:346) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_31]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_31]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.28.jar:8.0.28]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_31]
@guybedford
Copy link
Member

Nashorn is not currently supported as an environment.

The main environment hooks that need to be set up to get SystemJS to work are:

  • The ability to load a script dynamically
  • Getting the baseURI
  • Fetching a file
  • Eval

I'm more than happy to support Nashorn by wiring those in, and PRs are welcome, but it is not currently a development priority.

@manekinekko
Copy link
Author

thank you @guybedford
Do you have any clue on how you would implement those hooks in Java world ? I obviously need to do more investigations about Nashorn first :)

@guybedford
Copy link
Member

This would need to be integrated in the module loader itself, eg by altering the fetch implementation at https://github.com/ModuleLoader/es6-module-loader/blob/master/src/system-fetch.js to have a scenario for Nashhorn. This is not currently implemented in SystemJS, but we can consider it or a possible Nashorn build.

@manekinekko
Copy link
Author

@guybedford In Nashorn, you can call Java classes form JavaScript. So we can imagine having a Java implementation of the JavaScript fetch API which we will then use in SystemJS.
I will look at this more closely when I get more familiar with Nashorn ^^

@guybedford
Copy link
Member

Closing, to rather track any work here on the ES6 Module Loader project repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants