Skip to content

Modules doc direct execution test invalid under "type": "module" #34882

Open
@tshinnic

Description

@tshinnic

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    esmIssues and PRs related to the ECMAScript Modules implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions