Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

named exports are missing #38

Closed
trusktr opened this issue Mar 23, 2021 · 4 comments
Closed

named exports are missing #38

trusktr opened this issue Mar 23, 2021 · 4 comments

Comments

@trusktr
Copy link

trusktr commented Mar 23, 2021

import('https://esm.sh/@lume/element').then(({Element}) => {
  console.log(Element)
})

results in logging undefined instead of the expected value.

Note that the @lume/element package follows modern ESM standards and it works in Node.js ESM, or any tools that strictly follow Node ESM standards (like Webpack 5+).

Here's what the entry looks like: https://unpkg.com/@lume/element

@trusktr trusktr changed the title named exports of package are all inside the default export named exports are missing Mar 23, 2021
@zhoukekestar
Copy link

zhoukekestar commented Mar 24, 2021

Because esm.sh get named export by using node to eval your package.
You can get more details with fellow links:

And your @lume/package/dist/LumeElement use window object which will cause the eval fail.

Maybe we should try another way to get package's named export, puppeteer or something browser-like environment instead of node eval.

@trusktr
Copy link
Author

trusktr commented Mar 24, 2021

Yeah, it is a browser lib that uses window.

I think if the aim is to support ESM, the exports should be statically extracted without having to run the module. That's the whole benefit of ESM static imports (but not import() function).

Random ideas: use Babel or TypeScript compilers to get an AST, then read the exports from there. That would be a more realistic way to do it I think. It would not require running any code (that can be left to the end user to decide where they will run the code).

@ije
Copy link
Member

ije commented Mar 24, 2021

@trusktr thanks, yes you are right, i have a plan to rewrite the peer.js using AST to get right export names, but too busy currently...in fact there was a PR #33 to try to fix this but will affect other packages so i reverted. any way i will fix it ASAP

@ije
Copy link
Member

ije commented Mar 29, 2021

Screenshot 2021-03-30 at 02 54 19

fixed, pls try again, thanks~

@ije ije closed this as completed Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants