Search code examples
javascriptecmascript-6es5-shim

Migrating es5 to es6 export default


I am trying to migrate a code from es5 to es6, I am quite new in both, if someone could help me, I will be very thankful.

es5 version:

lib.js

module.exports = {
    foo1: function () { 
        this.foo2() {
           ... 
        }
    },
    foo2: function () { 
        ...
    }
}

main.js

const Lib = require("./lib");
Lib.foo1( { ... });

es6 version - I am trying:

lib.ts

export default { 
    foo1() {
        this.foo2(() => {
            ... 
        });                 
    },
    foo2(){ ... }
}

main.ts

import * as Lib from "./lib";
Lib.foo1({ ... })

The problem is in my main.ts foo1 can not be resolved. Any idea or recommendation?

Thank!


Solution

  • It should be just

    import Lib from "./lib";
    

    Otherwise, if you use * as notation you could access default export with Lib.default, but this is unnecessary.