Skip to content

require('apecs') fails: exports map has no default/require condition #1

Description

@k9p5

Summary

require('apecs') throws on Node 20.19 (the engines floor), even though Node supports require(esm) there.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in node_modules/apecs/package.json
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'

Cause

Every entry in the exports map in package.json declares only types and import. There is no require or default condition, so a CommonJS resolver finds no match at all. This affects any CJS consumer: Jest without ESM mode, older bundler configs, ts-node in CJS mode, and plain require in Node scripts.

Repro

mkdir smoke && cd smoke && npm init -y && npm i apecs@0.1.0
node -e "console.log(require('apecs').VERSION)"

Suggested fix

Add a default condition to each subpath pointing at the same ESM file. Node >= 20.19 resolves it through require(esm):

".": {
  "types": "./dist/index.d.ts",
  "import": "./dist/index.js",
  "default": "./dist/index.js"
}

Same for ./react, ./solid and ./internal. No CJS build is needed. Found by a post-publish smoke test of 0.1.0.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions