Skip to content
This repository was archived by the owner on Jun 24, 2025. It is now read-only.
This repository was archived by the owner on Jun 24, 2025. It is now read-only.

support for CommonJS module system #43

@HermannGruber

Description

@HermannGruber

We have setup an express app with TypeScript, and target CommonJS modules (which is still the default in TypeScript). Consequenty, we don't have "type": "module" in package.json. When we install a version => 2.0.0 of express-request-id, and start the app, it crashes with the following error:

/Users/hermangruber/IdeaProjects/express-example/dist/index.js:8
const express_request_id_1 = __importDefault(require("express-request-id"));
                                             ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/hermangruber/IdeaProjects/express-example/node_modules/express-request-id/index.js from /Users/hermangruber/IdeaProjects/express-example/dist/index.js not supported.
Instead change the require of /Users/hermangruber/IdeaProjects/express-example/node_modules/express-request-id/index.js in /Users/hermangruber/IdeaProjects/express-example/dist/index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/hermangruber/IdeaProjects/express-example/dist/index.js:8:46) {
  code: 'ERR_REQUIRE_ESM'
}

A minimal repro using the latest version of express-request-id can be found here:
https://github.com/HermannGruber/express-example

BTW, we tried to work around the issue by converting our app in full to ES2020 modules, but it seems that the rest of the ecosystem is not yet fully migrated to ESM. For example, jest 29.5 has only experimental support for ESM: https://jestjs.io/docs/ecmascript-modules

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions