Skip to content

__dirname is not defined when bundling h3-js for ESM environments #216

@veech

Description

@veech

Description

When using h3-js in an ESM bundler environment (e.g., Nitro/Rollup for Vercel serverless), the build fails with:

ReferenceError: __dirname is not defined in ES module scope

Cause

The compiled out/libh3.js (Emscripten output) references __dirname for Node.js environment detection and file path resolution. This works in CommonJS but fails in ES modules where __dirname doesn't exist.

Environment

  • Bundler: Rollup (via Nitro)
  • Target: Vercel serverless (ESM)
  • h3-js version: 4.4.0

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