Skip to content

[bug] CJS projects cannot resolve subpath exports (evlog/nestjs, evlog/otlp, etc.) #159

@spichen

Description

@spichen

Description

Problem

All subpath exports in evlog only define an "import" condition:

  "./nestjs": {
    "types": "./dist/nestjs/index.d.mts",
    "import": "./dist/nestjs/index.mjs"
  }

Node's CJS require() resolver does not match the "import" condition, so any project that compiles to CommonJS (e.g. NestJS with SWC, which is NestJS's default compiler) gets:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './nestjs' is not defined
by "exports" in node_modules/evlog/package.json

This affects all subpath exports, not just ./nestjs.

Expected behavior

require('evlog/nestjs') should resolve successfully in CJS projects, since Node 22+ can require() .mjs files when the export condition matches.

Suggested fix

Add a "default" condition to each subpath export. This is the lowest-effort fix and works for both ESM import and CJS require() on Node 22+:

  "./nestjs": {
    "types": "./dist/nestjs/index.d.mts",
    "import": "./dist/nestjs/index.mjs",
    "default": "./dist/nestjs/index.mjs"
  }

Reproduction

evlog: 2.4.1
Node: 22.14.0
NestJS 11 with SWC (compiles to CJS by default)

Logs

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions