Skip to content

require.main is undefined #11

Open
@jacobdweightman

Description

@jacobdweightman

In Node, a common idiom for checking if the current module is the one that was directly invoked is if (require.main === module) { ... }. Here are the docs.

This works as expected when the module is "inlined" in the top-level IIFE of the generated JavaScript code (see my other issue), but when this code is used inside of a defined module this condition fails because require is not the expected object.

This seems to be caused by require being provided by dependency injection, because the injected require object is a function rather than its usual object value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions