cdklabs / jsii-docgen

Generates reference documentation for jsii modules
Apache License 2.0
50 stars 13 forks source link

Error: unable to determine assembly since module does not have any types #1104

Open dvonessen opened 1 year ago

dvonessen commented 1 year ago

Hi, I have a problem with generating API documentation with jsii-docgen for the python library. Given module layout:

src/
  core/several_files.ts
  addons/
    aws/
      index.ts
    index.ts
  index.ts

The following problem happens as soon as I add a named export on the second level of the library.

# This works!
src/index.ts
export * from "./core"
export * as addons from "./addons"
# As soon as adding follwoing to the src/addons/index.ts
export * as aws from "./aws"

Error message:

 npx projen && npx projen compile && npx projen package-all && rm -f docs/api/api.*.md && npx projen docs:api
πŸ‘Ύ default | ts-node --project tsconfig.dev.json .projenrc.ts
πŸ‘Ύ Installing dependencies...
πŸ‘Ύ install | yarn install --check-files
yarn install v1.22.19
[1/5] πŸ”  Validating package.json...
[2/5] πŸ”  Resolving packages...
success Already up-to-date.
✨  Done in 2.77s.
πŸ‘Ύ Installing dependencies...
πŸ‘Ύ install | yarn install --check-files
yarn install v1.22.19
[1/5] πŸ”  Validating package.json...
[2/5] πŸ”  Resolving packages...
success Already up-to-date.
✨  Done in 3.45s.
πŸ‘Ύ compile | jsii --silence-warnings=reserved-word
πŸ‘Ύ package-all Β» package:js | jsii-pacmak -v --target js
[jsii-pacmak] [INFO] Found 1 modules to package
[jsii-pacmak] [INFO] Packaging NPM bundles
[jsii-pacmak] [INFO] Loading jsii assemblies and translations
[jsii-pacmak] [INFO] Packaging 'js' for @gcix/gcix
[jsii-pacmak] [INFO] js finished
[jsii-pacmak] [INFO] Packaged. npm pack (37.2s) | js (0.1s) | load jsii (0.0s) | cleanup (0.0s)
πŸ‘Ύ package-all Β» package:python | jsii-pacmak -v --target python
[jsii-pacmak] [INFO] Found 1 modules to package
[jsii-pacmak] [INFO] Packaging NPM bundles
[jsii-pacmak] [INFO] Loading jsii assemblies and translations
[jsii-pacmak] [INFO] Packaging 'python' for @gcix/gcix
[jsii-pacmak] [INFO] python finished
[jsii-pacmak] [INFO] Packaged. npm pack (34.2s) | python (20.5s) | load jsii (0.0s) | cleanup (0.0s)
πŸ‘Ύ docs:api Β» compile | jsii --silence-warnings=reserved-word
πŸ‘Ύ docs:api | npx jsii-docgen -l typescript -l python --readme false --output ./docs/api/api
Error: unable to determine assembly since module does not have any types: @gcix/gcix.addons
    at PythonTranspile.getParentModule (/Users/danielvonessen/git/gitlab/dvonessen/gcix/node_modules/jsii-docgen/lib/docgen/transpile/transpile.js:393:19)
    at PythonTranspile.moduleLike (/Users/danielvonessen/git/gitlab/dvonessen/gcix/node_modules/jsii-docgen/lib/docgen/transpile/python.js:240:35)
    at PythonTranspile.type (/Users/danielvonessen/git/gitlab/dvonessen/gcix/node_modules/jsii-docgen/lib/docgen/transpile/python.js:219:33)
    at /Users/danielvonessen/git/gitlab/dvonessen/gcix/node_modules/jsii-docgen/lib/docgen/view/interface.js:16:81
    at Array.map (<anonymous>)
    at new Interface (/Users/danielvonessen/git/gitlab/dvonessen/gcix/node_modules/jsii-docgen/lib/docgen/view/interface.js:16:57)
    at /Users/danielvonessen/git/gitlab/dvonessen/gcix/node_modules/jsii-docgen/lib/docgen/view/interfaces.js:9:25
    at Array.map (<anonymous>)
    at new Interfaces (/Users/danielvonessen/git/gitlab/dvonessen/gcix/node_modules/jsii-docgen/lib/docgen/view/interfaces.js:9:14)
    at new ApiReference (/Users/danielvonessen/git/gitlab/dvonessen/gcix/node_modules/jsii-docgen/lib/docgen/view/api-reference.js:30:27)
πŸ‘Ύ Task "docs:api" failed when executing "npx jsii-docgen -l typescript -l python --readme false --output ./docs/api/api" (cwd: /Users/USERNAME/git/gitlab/USERNAME/gcix)

The repo can be found at https://gitlab.com/gcix/gcix.

antoniordz96 commented 10 months ago

One thing to note this only seems to be when generating api documentation for other languages other than typescript.

mrgrain commented 5 months ago

@gcix/gcix.addons needs to be a jsii library as well or it's identified wrongly as needing to be one.

TimothyJones commented 1 month ago

I've also run into this, but with java.

The command:

npx jsii-docgen -f json -l java

in my publicly available jsii project @contract-case/case-definition-dsl, produces the following error:

Error: unable to determine assembly since module does not have any types: @contract-case/case-definition-dsl.mocks
    at JavaTranspile.getParentModule (/Users/home/office/contract-case/contract-case/node_modules/jsii-docgen/lib/docgen/transpile/transpile.js:394:19)
    at JavaTranspile.moduleLike (/Users/home/office/contract-case/contract-case/node_modules/jsii-docgen/lib/docgen/transpile/java.js:78:33)
    at JavaTranspile.type (/Users/home/office/contract-case/contract-case/node_modules/jsii-docgen/lib/docgen/transpile/java.js:96:33)

@contract-case/case-definition-dsl.mocks is a submodule of my jsii project. It only re-exports other types though - perhaps that's the problem?

mrgrain commented 1 month ago

in my publicly available jsii project @contract-case/case-definition-dsl, produces the following error:

This seems to be because the submodule @contract-case/case-definition-dsl.mocks doesn't define any types on it's own. It's just a wrapper around some other submodules. Definitely a bug.

dverdonschot commented 2 weeks ago

I am facing the same issue. jsii-docgen fails when creating python documentation because one of my index.ts files only exports submodules, and doesn't have any types. I tried manually adding a type, but have not been successful so far.

jsii-docgen --split-by-submodule -l python -o ./docs/API_documentation/Python/API.md
Error: unable to determine assembly since module does not have any types: @library/custom-cdk-constructs.cloud_products
    at PythonTranspile.getParentModule (/usr/local/lib/node_modules/jsii-docgen/lib/docgen/transpile/transpile.js:394:19)
    at PythonTranspile.moduleLike (/usr/local/lib/node_modules/jsii-docgen/lib/docgen/transpile/python.js:244:35)
    at PythonTranspile.type (/usr/local/lib/node_modules/jsii-docgen/lib/docgen/transpile/python.js:223:33)
    at PythonTranspile.callable (/usr/local/lib/node_modules/jsii-docgen/lib/docgen/transpile/python.js:185:27)
    at new Initializer (/usr/local/lib/node_modules/jsii-docgen/lib/docgen/view/initializer.js:9:37)
    at new Class (/usr/local/lib/node_modules/jsii-docgen/lib/docgen/view/class.js:24:32)
    at new Construct (/usr/local/lib/node_modules/jsii-docgen/lib/docgen/view/construct.js:7:26)
    at /usr/local/lib/node_modules/jsii-docgen/lib/docgen/view/constructs.js:10:25
    at Array.map (<anonymous>)
    at new Constructs (/usr/local/lib/node_modules/jsii-docgen/lib/docgen/view/constructs.js:10:14)
TimothyJones commented 2 weeks ago

I was able to generate java documentation with the following workaround type (note that you'll need to run jsii again before jsii-docgen, or it won't know you've changed anything)

/**
 * Empty class to make jsii-docgen happy with this module
 */
export class Empty {}

Unfortunately, if I annotate it @internal so that the documentation isn't generated, the error comes back - so it's not a great workaround.