Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

104
Views
ES6 named imports in defineAsyncComponent

I'd like to async load some elements of my web app:

This is the old import:

import {Popover, PopoverButton, PopoverPanel} from '@headlessui/vue'

export default {
    components: {
        Popover,
        PopoverButton,
        PopoverPanel,
    },
...

Now I would like to do this:

import {defineAsyncComponent} from "vue";

export default {
    components: {
        Popover: defineAsyncComponent(() =>
            import( {Popover} from "@headlessui/vue" ) // This does not work as I get the error " ')' expected"
        ),
        ...
    },
...

Any idea how I could solve this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Static import is a statement and isn't supposed to be used anywhere but at the top of a module. Dynamic import() is an expression and follows JavaScript syntax that is used in expressions.

import() returns a promise of module exports. It should be:

Popover: defineAsyncComponent(async () => {
 return (await import("@headlessui/vue")).Popover;
})

Tree shaking is disabled for dynamically imported module and needs to be annotated for a bundler, e.g. Webpack.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!