Announcement

Collapse
No announcement yet.

Custom ES6 controller: cannot use import statement outside a module

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom ES6 controller: cannot use import statement outside a module

    I created files according to this page. The following works as expected:

    Code:
    define('calendar2:controllers/calendar2', ['controllers/record'], function (Dep) {
      return Dep.extend({
          actionHello: function (options) {
              console.log('action: hello');
          },
      });
    });
    Console:
    Code:
    action: hello
    However, this does not work:
    Code:
    import Controller from 'controllers/record';
    
    class Calendar2Controller extends Controller {
      actionHello(options) {
        console.log("action: hello")
      }
    }
    
    export default Calendar2Controller;
    ​
    Console:
    Click image for larger version

Name:	Screenshot 2023-09-25 at 16.13.06.png
Views:	243
Size:	60.6 KB
ID:	97891

    The source in the developer window shows an anonymous function, which is not in my file:

    Click image for larger version

Name:	Screenshot 2023-09-25 at 16.14.50.png
Views:	153
Size:	111.4 KB
ID:	97892

    How is this supposed to work?

  • #2
    This issue is also being tracked in Github.

    Comment


    • #3
      This has been figured out. Please see the issue on Github in my previous post for more details.

      Comment


      • #4
        Originally posted by bandtank View Post
        This has been figured out. Please see the issue on Github in my previous post for more details.
        Hi bandtank can you give that issue link? I have done but not found.

        Comment


        • #5
          You can use ES6 modules only from within an Espo module, it's not supported for custom folder customizations.

          When you run init from the ext-template repository, the script will ask whether you want to use ES6, but it will only work for new extensions you develop.

          Comment


          • #6
            One alternative is not to use ES6 modules and continue using AMD modules as before.

            Per yuri , the AMD syntaxis will continue to be supported "maybe forever" and curently the ES6 modules are actually transpiled back to AMD modules for execution.

            The main advantage of using ES6 modules, for those that care about it, is the support from IDE applications like PhpStorm.

            Comment

            Working...
            X