<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Loading ES6 imports and Modules</title><link>https://answers.axonivy.com/questions/4431/loading-es6-imports-and-modules</link><description>&lt;p&gt;Hello,
So i was follwoing the xample in the HTMLDialogDemos, and I tried to create an es6 module and import it. This worked, however, the imports that my module require are not being imported correctly. This is due to the fact that ES6 imports dont automatically ad the "ln=xpertivy-3-webContent" query param that its calling module got. &lt;/p&gt;
&lt;p&gt;To be clear, i imported page.js via &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;h:outputScript a:type="module" library="js/PureHtmlDialog"
    name="page.js"&amp;gt;
&amp;lt;/h:outputScript&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which gets the file at&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;a href="http://localhost:8081/ivy/faces/javax.faces.resource/resources/js/PureHtmlDialog/page.js?ln=xpertivy-3-webContent&amp;amp;xv=124700577218"&gt;http://localhost:8081/ivy/faces/javax.faces.resource/resources/js/PureHtmlDialog/page.js?ln=xpertivy-3-webContent&amp;amp;xv=124700577218&lt;/a&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which attempts to import &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import {Button,Column,Header} from "../component.js";
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;which in turn gets the URL&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;a href="http://localhost:8081/ivy/faces/javax.faces.resource/resources/js/component.js"&gt;http://localhost:8081/ivy/faces/javax.faces.resource/resources/js/component.js&lt;/a&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;if I try to visit the URL&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&lt;a href="http://localhost:8081/ivy/faces/javax.faces.resource/resources/js/component.js?ln=xpertivy-3-webContent"&gt;http://localhost:8081/ivy/faces/javax.faces.resource/resources/js/component.js?ln=xpertivy-3-webContent&lt;/a&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;then i can see the file correctly. &lt;/p&gt;
&lt;p&gt;I also tried to, inside the folder of the HTML dialog itself, to put a javascript file and import it with a plain script tag. This didnt work, and actually crashed the page. &lt;/p&gt;
&lt;p&gt;Is there a better way to do javascript file imports and es6 imports?&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/4431/loading-es6-imports-and-modules" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 17 Mar 2020 03:15:03 -0400</lastBuildDate><item><title>Answer by TareqK</title><link>https://answers.axonivy.com/questions/4431/loading-es6-imports-and-modules/4455</link><description>&lt;p&gt;We ended up using browserify to minify multiple files and babel to transpile them into ES5. This fixed this issue, and also allowed us to use NPM libraries.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">TareqK</dc:creator><pubDate>Tue, 17 Mar 2020 03:15:03 -0400</pubDate><guid>https://answers.axonivy.com/questions/4431/loading-es6-imports-and-modules/4455</guid></item><item><title>Answer by SupportIvyTeam</title><link>https://answers.axonivy.com/questions/4431/loading-es6-imports-and-modules/4434</link><description>&lt;p&gt;Hi &lt;/p&gt;
&lt;p&gt;Sadly our platform is not really build to use modules. You can add this get parameter to the module import like: &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import {Button,Column,Header} from "../component.js?ln=xpertivy-3-webContent";
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But the problem is that this parameter is dynamic. Means the number is the Process Model Version which provides this webContent.&lt;/p&gt;
&lt;p&gt;You could evaluate this over an other javascript function but then you have the problem that you have to load the module dynamically. And the Eclipse Javascript editor seems not to know this syntax.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;function getParam() {
  var scripts = document.getElementsByTagName("script");
  for (let script of scripts) {
    let src = script.getAttribute("src");
    if(src &amp;amp;&amp;amp; src.includes("ln=xpertivy-")) {
      return "?" + src.substring(src.indexOf("ln=xpertivy-"), src.indexOf("-webContent")) + "-webContent";
    }
  }
}

async function load() {
  let ext = await import("./extension.js" + getParam());
  ext.hello("test");
}

load();
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Anyway you need to be aware that ES6 is not supported by every browser (e.g ie11 only supports es5).&lt;/p&gt;
&lt;p&gt;Maybe its easier to simply import the js file the normal way...&lt;/p&gt;
&lt;p&gt;Kind regards&lt;/p&gt;
&lt;p&gt;Lukas&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">SupportIvyTeam</dc:creator><pubDate>Mon, 02 Mar 2020 07:36:44 -0500</pubDate><guid>https://answers.axonivy.com/questions/4431/loading-es6-imports-and-modules/4434</guid></item></channel></rss>