Description
Trying to emulate the Python __main__
check for testing purposes, I found the description in
"Accessing the Main Module" is unhelpful when package.json is set to ES modules mode "type": "module".
Suggesting if (require.main === module)
is unhelpful when both require
and module
are undefined and node throws errors.
I see at "No require, ..." that it says no require
variable is created in ESM mode, but it doesn't say module
disappears also.
I see old issues #21143 and linked #21150 but don't understand if they were asking for require
/module
in ESM mode.
The modules doc needs updating to reflect what happens under "type": "module" mode. That text has been left behind by the node.js support for ESM.
If there is elsewhere - or could be - hints as to how to emulate the Python __main__
check that'd be of interest to more than a few people.