es6 equivalent for module.exports
Asked Answered
H

1

0

What's the ES6 equivalent for module.exports

I want to get the value of foo from an import statement

module.exports = {
    foo: function (a) {
    }
}

Tried:

export default {
    foo: function (a) {
    }
}

The way first one is imported is using:

var file;
var filename = root + "/" + fileStats.name;
file = require(path.resolve(filename));

I want to use ES6 import statement. I read somewhere that this isn't supported however would like to still know if there's a work around this.

Hinze answered 12/6, 2016 at 9:36 Comment(0)
H
3

Not sure what you're trying to do because in the code you supplied you did not consume the actual foo method from the object you imported.

But if I understand correctly, you could achieve this in one of 2 ways:

export default function foo(a) { };

and consume the module with:

import foo from './<filename>.js';

Or alternatively, don't use the default export:

export function foo(a) {};

and consume with:

import { foo } from './<filename>.js';
Humanity answered 17/6, 2016 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.