Skip to content

Refactor CommonJS syntax (require) to ES Module syntax #2763

@gerteck

Description

@gerteck

Please confirm that you have searched existing issues in the repo

Yes, I have searched the existing issues

Any related issues?

This is a sub issue and blocker for #2615

What is the area that this feature belongs to?

Code Quality

Is your feature request related to a problem? Please describe.

We are currently using legacy CommonJS syntax (require/module.exports) throughout the project. While this works with our current build configuration, it is creating significant technical debt and blocking our migration to ES Modules (ESM).

  • Ultimately we want to switch our build output to native ES Modules (ESM) to support modern environments and tree-shaking.
    • However, TypeScript does not automatically rewrite CommonJS runtime syntax such as require and module.exports. If we emit ESM without first refactoring these usages to import/export, the generated code will fail at runtime because require is not available in native ESM.
      --

Describe the solution you'd like

Standardize on the ES Module syntax (import / export) immediately. Decouples the syntax migration from the configuration migration, allowing us to safely adopt modern syntax now while maintaining our current build pipeline.

  1. Refactor Syntax: Systematically replace require statements with import statements.
  2. Add Type Definitions: Create local .d.ts files for untyped dependencies to ensure the new import syntax is fully typed. (Need to find a suitable place and configs appropriately)

--

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions