Using ES Modules in krpano plugin

  • More and more libraries are using modules to organise the code. it uses import statement to include the functionality inside javascript.

    I have been trying to use such packages inside krpano javascript plugin, but I have not been able to do so using various approaches.

    Attempt 1: Using the import statement inside the plugin

    Fails as krpano throws a parsing error on import statements:

    Code
    ERROR: parsing './plugins/plugin.js' failed:SyntaxError: unexpected garbage after function body, starting with 'from'

    Attempt 2: declaring the modules in the main page or seperate .js

    Fails with: Uncaught ReferenceError: <module_name> is not defined.


    Anybody any tips on how to mix (krpano plugin) javascript with ES modules?

  • Hi,

    static import statements only work in .js files that are loaded directly by the Browser.

    But the krpano Javascript plugins are dynamic code, there only the import() function can be used:

    import() - JavaScript | MDN (mozilla.org)


    Btw - in the next release (1.22) there will be also an example plugin included that uses the import() function.

    Best regards,
    Klaus

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!