Skip to content

Packaged ESM app crashes at startup when dependency exports is not CJS-resolvable #281

Description

@JustasMonkev

What version of pkg are you using?

@yao-pkg/pkg@6.20.0

What version of Node.js are you using?

v25.6.0

What operating system are you using?

macOS, Apple Silicon

What CPU architecture are you using?

Apple M4

What Node versions, OSs and CPU architectures are you building for?

node22-macos-arm64

Describe the Bug

A packaged ESM app crashes at startup when it imports a package whose exports map is valid for ESM import but not resolvable through CommonJS require().

Plain Node runs the app correctly. The packaged binary builds successfully, but crashes at runtime.

I created a minimal repro repo here:

https://github.com/JustasMonkev/pkg-esm-runtime-repro

There are two related cases in the repro:

  1. ESM-only package with only an import condition:
{
  "exports": {
    ".": {
      "import": "./index.mjs"
    }
  }
}

### Expected Behavior

Not to crash

### To Reproduce

git clone https://github.com/JustasMonkev/pkg-esm-runtime-repro.git
cd pkg-esm-runtime-repro
npm install
npm run check
npm run e2e

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