Use JavaScript-Class in Script-Tag

22 Views Asked by At

I have a Laravel application with Blade templates and script tags. I try to import a javascript class, but I get the error message: Uncaught SyntaxError: Cannot use import statement outside a module

Script class :

 class DummyClass {

    constructor() {
    }

    testValidate(){
        return false;
    }
 } 

and i need it in the

@push('custom-scripts')
    <script type="text/javascript">

     import DummyClass from "<PATH TO THE MIX-DIST-FOLDER WITH URL>";

      let dummy = new DummyClass()
 

   </script>
@endpush

What is the reason and how can I use the class in the script tag?

0

There are 0 best solutions below