Skip to content

Bug: __dirname is not defined when using sandbox.start({}) with ESM #37

@AlexKushnir1

Description

@AlexKushnir1

When using near-sandbox in a project configured for ESM (ECMAScript Modules), calling:

await sandbox.start({});

throws a runtime error:

ReferenceError: __dirname is not defined

This happens because __dirname is not available in ESM environments by default.

For now I see two ways:

-> Fully migration to ESM
Pros:

  • No reliance on CommonJS globals;
  • Simplifies long-term maintenance

Cons:

  • Breaking change for CommonJS consumers

-> Dual output using conditional exports to let Node choose the appropriate file with dirName func
Pros:

  • Backward-compatible
  • Works for both CJS and ESM consumers

Cons:

  • Complexity

I could work on it if get some insturctions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions