Custom ES6 controller: cannot use import statement outside a module

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bandtank
    Active Community Member
    • Mar 2017
    • 379

    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:	361
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:	271
Size:	111.4 KB
ID:	97892

    How is this supposed to work?
  • bandtank
    Active Community Member
    • Mar 2017
    • 379

    #2
    This issue is also being tracked in Github.

    Comment

    • bandtank
      Active Community Member
      • Mar 2017
      • 379

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

      Comment

      • flanklin
        Junior Member
        • Oct 2022
        • 19

        #4
        Originally posted by bandtank
        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

        • yuri
          Member
          • Mar 2014
          • 8440

          #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.
          If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

          Comment

          • telecastg
            Active Community Member
            • Jun 2018
            • 907

            #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...