Skip to content

Feature suggestion: async modules #309

Description

@burtek

Version 13.1.0 introduced esm configs support. Under the hood all .js/.cjs/.mjs configs are imported via:

const require = createRequire(import.meta.url);

This works well for cjs/esm interoperability, but it means async esm modules cannot be used:

$ commit-and-tag-version --dry-run
node:internal/modules/esm/module_job:314
    throw new ERR_REQUIRE_ASYNC_MODULE(filename, parent, locations);
          ^

Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead. To see where the top-level await comes from, use --experimental-print-required-tla.
Required module: /some/project/.versionrc.js
Require stack:
- /some/project/node_modules/.pnpm/commit-and-tag-version@13.1.0_conventional-commits-filter@6.0.1_conventional-commits-parser@7.1.0/node_modules/commit-and-tag-version/lib/configuration.js

Enabling async modules would allow to use async node APIs (i.e. node:fs/promises API for dynamically finding all files to bump in a monorepo) as well as other async APIs (i.e. fetching partial configuration from external source like company internal API).

In addition to above (or as an alternative) support for async code could be achieved by allowing default export to be an async function, to be waited here:

config = jsConfiguration();

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