JavaScript - Reference not defined

Hello,

I want to use a JavaScript library inside an addon that I am currently working on.
I added the according @JavaScript annotation on my AbstractJavaScriptExtension (it is going to be an extension, not a component):

@JavaScript({"vaadin://addons/js/mylib.js"}) public class MyExtension extends AbstractJavaScriptExtension { } The library is located inside
src/main/resources/VAADIN/addons/mylib.js
.

Now inside my connector I want to use the library inside the extend() method that is calling a JSNI method:

[code]
@Connect(MyExtension.class)
public class MyExtensionConnector extends AbstractExtensionConnector {

@Override
protected void extend(ServerConnector target) {
    callJsniMethod();
}

private native void callJsniMethod() /*-{
    var myVar = new $wnd.MyLib.MyClass();
}-*/;

}
[/code]Now by using the console inside the Chrome Developer Tools I can see that I get an error that “MyLib” is not defined at the moment of execution (I set a breakpoint).

Later on, once the page is fully loaded, I can create an instance inside the console.

Am I doing something wrong or is the library loaded too late or whats going on here?

Thank you already for your help!

Ok, I found out a way to mak it work:

In the script a global vairable was set using:

let MyVar = new MyLib;

It seems that this is not working because the script is loaded/executed in a non global scope by vaadin.
That way the global object does not exist and is not accessible.

Maybe a vaadin guy could confirm this?