Skip to content

The order of the fields in the exports object of package.json breaks automatic discovery of entry points #2988

@K1DV5

Description

@K1DV5

Search terms

exports, automatic discovery, package.json, order

Expected Behavior

I run npx typedoc like the docs say and it should just work.

Actual Behavior

If the types comes before default or import, TypeDoc doesn't find the source files and doesn't generate the docs.

Steps to reproduce the bug

Only have these three files:

package.json

{
    "name": "pkg1",
    "version": "1.0.0",
    "type": "module",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "files": ["dist", "src"],
    "exports": {
        ".": {
            "types": "./dist/index.d.ts",
            "default": "./dist/index.js"
        }
    },
    "author": "",
    "license": "ISC",
    "description": "",
    "dependencies": {
        "typedoc": "^0.28.8",
        "typescript": "^5.8.3"
    }
}

tsconfig.json

{
  "compilerOptions": {
    "moduleResolution": "nodenext",
    "target": "es2022",
    "module": "nodenext",
    "lib": ["es2022"],
    "declaration": true,
    "verbatimModuleSyntax": true,
    "isolatedModules": true,
    "resolveJsonModule": true,
    "noImplicitAny": false,
    "sourceMap": true,
    "declarationMap": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "checkJs": true,
    "outDir": "dist",
    "rootDir": "src"
  },
  "include": ["src"]
}

src/index.ts

export function foo(s: string) {
    console.log(s)
}

Command:

npx typedoc  --skipErrorChecking

Additional Info

I tracked the issue to this line in the typedoc source and it is because it checks them in that specific order. This, combined with the fact that it can't infer the source file from the declaration file given to types, produces this issue.

Also, I could just reorder all my exports, but the Node.js docs advise that default should come last. Maybe that doesn't apply to types. Also, I could set typedoc first. But that should not be necessary for a path that is available on the next entry. Or at least all of these nuances should be specified in the docs somewhere.

Environment

  • Typedoc version: 0.28.8
  • TypeScript version: 5.8.3
  • Node.js version: 22.16.0
  • OS: WSL AlmaLinux 10 on Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions