Skip to content

require("@cldmv/uuid") fails with ERR_REQUIRE_ASYNC_MODULE (top-level await in index.mjs) #49

Description

@Shinrai

Problem

@cldmv/uuid@1.2.4 cannot be loaded from CommonJS. index.cjs loads ./index.mjs via require(), and index.mjs uses top-level await:

try { await import("./devcheck.mjs"); } catch {}
const { UUID, ISSUER_CATEGORIES } = await import("@cldmv/uuid/main");

Node's synchronous require(esm) refuses any ESM graph that contains top-level await:

Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead.

Reproduced on Node 26.4.0 with node -e 'require("@cldmv/uuid")'. On Node versions without require(esm), the CJS entry fails with ERR_REQUIRE_ESM instead, so the require export has never worked.

Impact

Every CommonJS consumer is blocked, which prevents replacing npm uuid with @cldmv/uuid in CJS projects. For example, CLDMV/cldmv-node-chat#13 had to stay on uuid@^11 for this reason.

Fix

Replace the top-level awaits in index.mjs with static imports, so the ESM entry graph is synchronous. Static imports evaluate in source order, so devcheck.mjs still runs before the library module. devcheck.mjs must then ship in the package (it is already a no-op when installed under node_modules or when src/ is absent). index.cjs becomes a plain require("./index.mjs") re-export. Add a test that loads the package through require().

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreTouches core library / runtime source codepriority: highNeeds attention soon — not blocking, but don't let it sitstatus: implementedBuilt and deployed, but not yet fully tested/verifiedtype: bugSomething is broken or not behaving as expected

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions