typedoc: Unable to setup typedoc in a nx monorepo

Search terms

monorepo, nx

Question

Hey, I am having a similiar setup as in https://github.com/TypeStrong/typedoc/issues/2061 - a pretty large project as nx monorepo, which contains both web (React) apps and some standalone libraries.

I want to generate docs for the libraries which are located at path libs/data

The typedoc config is following, I’ve added one package products just for sake of testing/simplicity, but there are more:

{
  "out": "docs",
  "entryPointStrategy": "packages",
  "entryPoints": [
    "libs/data/products"
  ]
}

The package.json for the products package is following:

{
  "name": "@mycompany/products",
  "version": "0.0.1",
  "main": "./src/index.ts",
  "typedoc": {
    "entryPoint": "./src/index.ts",
    "readmeFile": "./README.md",
    "displayName": "@mycompany/products"
  }
}

However I am getting these errors:

error TS6305: Output file '...../libs/data/products/src/service.d.ts' has not been built from source file '..../libs/data/products/src/service.ts'.
  The file is in the program because:
    Root file specified for compilation
    
error TS6306: Referenced project '....../libs/data/products/tsconfig.lib.json' must have setting "composite": true
error TS6306: Referenced project '....../libs/data/products/tsconfig.spec.json' must have setting "composite": true

Any advices on how to fix it? Thanks in advance. Please note, that I cannot apply same solution of renaming every tsconfig file as mentioned in the linked issue above - the project is too large for that.

Node v.14.18.2 yarn 1.22.19 nx 13.1.2 typedoc 0.23 typescript 4.5.5 (I am aware of compatibiltiy issues with that typedoc version, however, typedoc@0.22 seems to be lack of the child package.json setup)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19

Most upvoted comments

@Gerrit0 here is minimal example: https://github.com/MrOnlineCoder/typedoc_nx_issue

With the following changes, documentation generates as expected.

diff --git a/libs/data/services/products-service/package.json b/libs/data/services/products-service/package.json
index 5e81c08..7281d96 100644
--- a/libs/data/services/products-service/package.json
+++ b/libs/data/services/products-service/package.json
@@ -4,6 +4,7 @@
   "typedoc": {
     "entryPoint": "./src/index.ts",
     "readmeFile": "./README.md",
-    "displayName": "@myapp/products-service"
+    "displayName": "@myapp/products-service",
+    "tsconfig": "tsconfig.lib.json"
   }
 }

Update: I’ve tried updating to latest typedoc version with tsconfig option support for separate packages and setting it to ‘tsconfig.lib.json’, but it didn’t work too:

TypeError: context.checker.getTypeOfSymbol is not a function
    at Object.convertProperty (.../node_modules/typedoc/dist/lib/converter/symbols.js:362:25)

Apparently I need to make the warning about running with unsupported versions of TypeDoc louder. TypeScript 4.5 is not supported. If you upgrade TypeScript, this error will go away.

When entryPointsStrategy is set to packages I get the error:

The option is entryPointStrategy, not entryPointsStrategy. For packages mode, you should also specify package directories containing package.json as your entry points, not files.

Can confirm inability to work with monorepo with nx and lerna

When entryPointsStrategy is set to packages I get the error:

error Tried to set an option (entryPointsStrategy) that was not declared.

But it is declared like this:

{
  "tsconfig": "./tsconfig.base.json",
  "entryPoints": [
    "packages/time/src/index.ts",
    "packages/ui/src/index.ts",
    "packages/utils/src/index.ts"
  ],
  "entryPointsStrategy": "packages",
  "exclude": [],
  "out": "docs",
  "name": "Insided Packages",
  "pretty": true
}

By any configuration it does not use child (leaf) package.jsons typedoc property. For example, I would like to use tsconfig.json files per package (some packages are react-based, some not).

And I would like to use a custom .md (in my case Changelog by Conventional Commits) on page of each package.