Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is (await import("node:process")).on undefined?

Title says it all.

Running

console.log((await import("node:process")).on)

Results in undefined being printed.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why is this the case?

If I use a static import, it works as expected:

import process from "node:process"

console.log(process.on)

>Solution :

The static import declaration is a default import, short for

import { default as process } from "node:process"
console.log(process.on)

The corresponding dynamic import would be

const { default: process } = await import("node:process");
console.log(process.on)

or

console.log((await import("node:process")).default.on)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading