Skip to content

CJS build has undeclared ESM-only dependencies, breaking use in CommonJS projects #200

@markedwards

Description

@markedwards

mockttp 4.x ships a CommonJS build (dist/) but depends on packages that are pure ESM-only, including at least get-port and milliparsec.

This causes a hard crash when mockttp is loaded in a CommonJS context:

Error: require() of ES Module node_modules/.pnpm/get-port@7.2.0/node_modules/get-port/index.js
from .../mockttp/dist/server/mockttp-server.js not supported.

Environment:

mockttp: 4.3.0
Node.js: 24.13
Package manager: pnpm (monorepo)
Project type: Next.js, no "type": "module" in package.json

How to reproduce:

Load mockttp in any CommonJS Node.js context — specifically one that doesn't have ESM interop handling, such as the VSCode Playwright extension's test runner process.

Note: this does not surface when running tests via the CLI, because Next.js/the test runner handles ESM interop transparently. It only becomes visible in plain CommonJS contexts.

Expected behaviour:

A package that ships a CJS build should either:

  • Only depend on CJS-compatible packages, or
  • Ship a proper dual CJS/ESM build and declare both in package.json exports, or
  • Use dynamic import() in the CJS build where ESM dependencies are required

Actual behaviour:

The CJS build hard-crashes with a require() of ESM error. Attempting to override get-port to an older version via pnpm overrides surfaces additional ESM-only dependencies (milliparsec), suggesting this is a systemic issue across multiple dependencies rather than a single transitive dependency problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions