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

This issue has been tracked since 2023-03-04.

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
ilg-ul wrote this answer on 2023-03-05

Another solution would be to add a configuration option like --packageJson to provide the path to the package.json file.

This would be preferred and also consistent with --readme

Note: in my project there is also a src/README.md file, and by default typedoc selects it, thus I have to explicitly specify "readme": "./README.md", in typedoc.json.

It would be natural to also specify "packageJson": "./package.json",.

Gerrit0 wrote this answer on 2023-03-05

It seems reasonable to me to ignore a package.json if there is no name field, should take care of the esm use case. The packageJson option might not be necessary then.

ilg-ul wrote this answer on 2023-03-05

Sure, the first solution is more automated, but would probably require a bit more effort to implement.

More Details About Repo
Owner Name TypeStrong
Repo Name typedoc
Full Name TypeStrong/typedoc
Language TypeScript
Created Date 2014-05-24
Updated Date 2023-03-19
Star Count 6487
Watcher Count 68
Fork Count 639
Issue Count 48

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date