tc39 / proposal-dynamic-import

import() proposal for JavaScript

Home Page:https://tc39.github.io/proposal-dynamic-import/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get named exports ?

koalex opened this issue · comments

// files/b.js

export const myVar = 1;
export default function () {}

// files/a.js

import b from './b.js';
export default { b: b };

// index.js

import('files/a.js').then(a => {
	console.log(a.b.myVar); // NOT WORKING !!!
        console.log(a.default.b.myVar); // NOT WORKING !!!
        console.log(a.default.b.default.myVar); // NOT WORKING !!!
});

what am I doing wrong ?

Thanks!

This kind of support question is best not asked on the specification repository, whose issue tracker is meant for issues with the specification. I'd suggest a place like StackOverflow.

@domenic I think the question was more like: "how do we import named exports from modules?"
Is this possible with current spec? Or does it import the whole file no matter what's inside?

Named exports are properly supported in the current spec. The promise resolves to the namespace object of the imported module.

The function in b.js is available as a.default.b, the variable is not accessible from the resolved a (it is not reexported by a.js).