1

I am converting old functional-based syntax Javascript to ES6 classes . Previously code was like this :

var SW;
if(SW.app === undefined) SW.app = {};
SW.app.NullLicense = (function () {
    "use strict";

    var NullLicense;
    NullLicense = function () { };
    NullLicense.prototype.handleLicense = function () {
        var t1 = new SW.app.Utility();
        return t1;
    };
    return NullLicense;
}());

Now with ES6 modules the code is like this

import {Utility} from './Utility.js'
export class NullLicense  {
    "use strict";
    constructor(){ };
   handleLicense  () {
        var t1 = new Utility();
        return t1;
    }
};

Since previously every module was concatenated to global SW variable we didn't have to worry about the dependencies issue. In app/asset we have our manifest file application.js . It loads all the js files in the code base. Now since we have export and import commands in every file , I am getting this error that export declarations may only appear at top level of a module. I want to know what can be the workaround for this .

Thanks

Deepak
  • 49
  • 1
  • 6
  • You're using a highly outdated tool which assembles your assets by just copy-pasting them together. While it may be possible to get it work its most likely a huge waste of time compared to switching to a JS based assets system that actually understands ES6 modules. I would recommend that you just leave the JS it as is for now and focus on updating the Rails application. – max Mar 09 '22 at 11:32

1 Answers1

-2

Try using Webpacker gem or webpack.

Skyler
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 08 '22 at 21:46