Skip to content

Enforce key order in "exports" field (import before require) #727

@teleskop150750

Description

@teleskop150750

Clear and concise description of the problem

Description

Currently, tsdown generates the exports field in package.json without a strictly defined order. According to Node.js documentation and best practices (Dual Package Hazard prevention), the order of keys in the exports object is significant because Node.js uses the first matching condition.

Proposed Change

Ensure that the generated exports object follows the recommended order:

  1. types
  2. import
  3. require
  4. default

Example of desired output:

"exports": {
  ".": {
    "import": "./dist/index.mjs",
    "require": "./dist/index.cjs"
  },
  "./package.json": "./package.json"
},

Current behavior

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions