typedoc: Fails to identify name/version due to the presence of an unexpected package.json

Search terms

warning name version package.json

Expected Behavior

Pick the name & version from the project package.json.

Actual Behavior

Tries to get the name and version from src/package.json and fails, since in that file there is only a type: module definition, (required by the dual CommonJS/ES6 module nature of the project).

Steps to reproduce the bug

Assuming the entry point is src/index.ts, add a minimal src/package.json like:

{
  "type": "module"
}

This will confuse typedoc, which will no longer be able to identify the name/version:

> typedoc --logLevel Verbose

Using TypeScript 4.9.5 from ./node_modules/typescript/lib
Converting with 1 programs 1 entry points
Finished getting entry points in 724ms
Begin readme.md/package.json search at ./src <---
warning The --name option was not specified, and package.json does not have a name field. Defaulting project name to "Documentation".
warning --includeVersion was specified, but package.json does not specify a version.
Finished conversion in 124ms
Validation took 1ms
Renderer: Loading highlighter took 374ms
Documentation generated at ./docs
HTML rendering took 664ms

I think that a better strategy would be to iterate to the parent folder and try to read the name/version from there, until the project root is reached.

As a partial workaround, I also added the project name to this short package.json, but the version remained undefined.

Environment

  • Typedoc version: 0.23.26
  • TypeScript version: 4.9.5
  • Node.js version: 14.21.2
  • OS: macOS 12.6.3

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15

Commits related to this issue

Most upvoted comments

Basically every plugin modifies some typedoc behavior… a projectVersion option seems like a useful option in case the package.json has a bad version.

0.24 completely reworks packages mode so that it effectively runs TypeDoc in each package directory, then merges the results together, so versions in packages/foo/package.json will be correctly applied

Here is a suggestion.

After playing with typedoc, I realise that we don’t necessarily want the version tag from package.json. We may want it from lerna.json for example. Or god knows wherever else.

Is it possible more flexible to specify a --version flag like typedoc --version 0.0.1 . I know this conflicts with another tag which displays the version.

I leave issues open until the fix has been released - this is a part of 0.24, so isn’t out yet

If this problem was fixed by 63a521c, you can close this issue.