Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 Dynamic importing with namespace?

When using dynamic imports, can I define what I want to import like regular imports?

For example:

import Person from '/classes.js'

As dynamic:

await import('Person from /classes.js') //Incorrect obviously
like image 582
Mojimi Avatar asked Oct 29 '25 10:10

Mojimi


1 Answers

Dynamic imports will hand you everything from within the module. You can use destructuring the extract the pieces you want.

const { Person } = await import('/classes.js');
like image 180
Mike Cluck Avatar answered Oct 31 '25 02:10

Mike Cluck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!