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

Default export is incorrect when imported via dynamic import #1830

Closed
2 of 3 tasks
DreierF opened this issue Jan 31, 2021 · 0 comments
Closed
2 of 3 tasks

Default export is incorrect when imported via dynamic import #1830

DreierF opened this issue Jan 31, 2021 · 0 comments

Comments

@DreierF
Copy link
Contributor

DreierF commented Jan 31, 2021

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

When using import('clipboard') to dynamically load the Clipboard.js library, the resulting module looks like the following, with two default fields nested into each other:

image

in contrast when loading the library with a regular import ClipboardJS from 'clipboard' I directly get the constructor function or similarly with import * as clipboard from 'clipboard' the following object with only a single default field:

image

I would expect to get the same module shape also via import('clipboard'), which is also what Webpack produces.

Reproduction

Use the vanilla vite template, install clipboard and add the following code snippet to main.js

import('clipboard').then(({default: ClipboardJS})=>{
    new ClipboardJS('h1');
});

This fails with

Uncaught (in promise) TypeError: ClipboardJS is not a constructor
    at main.js:8

System Info

  • vite version: 2.0.0-beta.60
  • Operating System: MacOS
  • Node version: 14.15
  • Package manager (npm/yarn/pnpm) and version: yarn
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant