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

[commonjs] named export missing with v13 + dynamic imports #467

Closed
lazka opened this issue Jun 22, 2020 · 17 comments · Fixed by rollup/rollup#3648
Closed

[commonjs] named export missing with v13 + dynamic imports #467

lazka opened this issue Jun 22, 2020 · 17 comments · Fixed by rollup/rollup#3648

Comments

@lazka
Copy link

lazka commented Jun 22, 2020

  • Rollup Plugin Name: @rollup/plugin-commonjs
  • Rollup Plugin Version: 13.0.0
  • Rollup Version: 2.18.0
  • Operating System (or Browser): Firefox 77
  • Node Version: v12.18.1

How Do We Reproduce?

I'm including fabricjs via dynamic imports and the update from v12 to v13 removed the named export. Static imports still work though.

async function foo() {
    const x = (await import('fabric')).fabric;
    console.log(x); // this is undefined but wasn't with 12.0.0
}

foo();

This works though

import {fabric} from 'fabric';

I've created a small reproducer: https://github.com/lazka/rollup-bug-dynamic-import-exports

Expected Behavior

Named exports work the same with dynamic imports as with non-dynamic ones

Actual Behavior

They are missing in the dynamic case.

@shellscape
Copy link
Collaborator

Probably similar to #451

@lazka
Copy link
Author

lazka commented Jun 22, 2020

The weird thing is if I add a dummy static import at the top the dynamic one works again and provides the named export.

@lukastaegert
Copy link
Member

I think it is different from #451 and might be actually a bug in Rollup itself, specifically in how synthetic named exports interact with dynamic imports. Will need to investigate.

@lukastaegert
Copy link
Member

There will be a fix in Rollup, see rollup/rollup#3648. I will put it into the next patch release. This should fix this bug without necessary changes to this plugin.

@lukastaegert
Copy link
Member

Fixed in Rollup@2.18.1

@lazka
Copy link
Author

lazka commented Jun 27, 2020

Thank you!

edit: also confirming that things work again with 2.18.1 :)

@desmap
Copy link

desmap commented Aug 14, 2020

@lukastaegert it seems still to be broken with 2.25

Pls check the demo repo: https://github.com/desmap/project-refs

When you run it you get:

const { ObjectType, Field } = process.env.SHIM
        ^

TypeError: Cannot destructure property 'ObjectType' of '(intermediate value)(intermediate value)(intermediate value)' as it is undefined.

The dynamic import is in p1/index.ts:

const { ObjectType, Field } = process.env.SHIM
  ? await import('type-graphql/dist/browser-shim.js')
  : await import('type-graphql')

console.log(Field)

export default 'Hello World!'

You need to run it with NODE_OPTIONS="--experimental-top-level-await" npm run dev

It works with a static import ... from

CC @lazka

@lazka
Copy link
Author

lazka commented Aug 14, 2020

I'd suggest you open a new issue for this.

@desmap
Copy link

desmap commented Aug 14, 2020

@lazka I can do this but why a second issue about the exact same thing?

It's again about named export[s] missing with v13 + dynamic imports.. Maybe it doesn't work because I used a top-level await but this shouldn't be the reason (hopefully)... whatever it's not working.

@desmap
Copy link

desmap commented Aug 14, 2020

@lukastaegert let me know if you want a new issue about the my post above

@shellscape
Copy link
Collaborator

(Please remember to use the "Edit" feature for successive replies to help cut down on notification noise.)

@lukastaegert
Copy link
Member

Yes please, because even though the symptom is the same, the cause obviously isn't. This helps me with book-keeping and adds visibility so that others notice this issue and can have a look as well.

@lazka
Copy link
Author

lazka commented Aug 14, 2020

(For completeness sake I've tested my reproducer and it still works correctly with the latest versions of everything)

@desmap
Copy link

desmap commented Aug 17, 2020

@shellscape

(Please remember to use the "Edit" feature for successive replies to help cut down on notification noise.)

In this case it was on purpose. Github does not notify users added in an edit. Besides, pls be aware that your post creates unnecessary noise as well and is not welcoming.

@desmap
Copy link

desmap commented Aug 17, 2020

@lazka

(For completeness sake I've tested my reproducer and it still works correctly with the latest versions of everything)

Thanks for checking it out again. Did you test it with a top-level await?

@lazka
Copy link
Author

lazka commented Aug 17, 2020

Thanks for checking it out again. Did you test it with a top-level await?

No. I just want to rule out that this is a regression.

@rollup rollup locked as resolved and limited conversation to collaborators Aug 17, 2020
@shellscape
Copy link
Collaborator

@desmap I asked politely. Please heed the requests of maintainers. Locking as resolved to prevent further superfluous comments. If this becomes an issue for anyone else in the future, please create a new issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants