Using the dynamic import() function on Node.js

The dynamic import() loads the module and return a module object that contains all its exports. In order to access the default export use the default property of the module object:

const moduleA = await import('./moduleA');
moduleA.default();

// OR

const { default: moduleA } = await import('./moduleA');
moduleA();

Leave a Comment

error code: 521