marcj / typedoc-plugin-lerna-packages

A plugin for Typedoc that groups all Lerna packages into own TS module
MIT License
28 stars 15 forks source link

Error on first run #21

Closed eshcharc closed 4 years ago

eshcharc commented 4 years ago

I configured typedoc.json at the root of my lerna project. It seemed to recognize all the project packages and locations, but failed on the following issue.

Log:

C:\{project_path}\node_modules\typedoc-plugin-lerna-packages\dist\plugin.js:58 const copyChildren = context.project.children.slice(0); ^

TypeError: Cannot read property 'slice' of undefined at LernaPackagesPlugin.onBeginResolve (C:\{project_path}\node_modules\typedoc-plugin-lerna-packages\dist\plugin.js:58:55) at triggerEvents (C:\{project_path}\node_modules\typedoc\dist\lib\utils\events.js:128:43) at triggerApi (C:\{project_path}\node_modules\typedoc\dist\lib\utils\events.js:110:13) at eventsApi (C:\{project_path}\node_modules\typedoc\dist\lib\utils\events.js:21:18) at Converter.trigger (C:\{project_path}\node_modules\typedoc\dist\lib\utils\events.js:264:13) at Converter.resolve (C:\{project_path}\node_modules\typedoc\dist\lib\converter\converter.js:180:14) at Converter.convert (C:\{project_path}\node_modules\typedoc\dist\lib\converter\converter.js:91:30) at CliApplication.convert (C:\{project_path}\node_modules\typedoc\dist\lib\application.js:72:39) at CliApplication.bootstrap (C:\{project_path}\node_modules\typedoc\dist\lib\cli.js:45:34) at Object. (C:\{project_path}\node_modules\typedoc\bin\typedoc:5:5) error Command failed with exit code 1.

eshcharc commented 4 years ago

B.T.W when I added typedoc.js as explained in the README, it did not recognize the configuration, passed the build, but created no artifacts.

eshcharc commented 4 years ago

typedoc.json:

{
  "name": "Project name",
  "mode": "modules",
  "out": "docs",
  "readme": "README.md",
  "exclude": [
    "**/node_modules/**", 
    "**/*.spec.ts",
    "**/tests/**/*.ts"
  ],
  "excludePrivate": true
}
marcj commented 4 years ago

Does typedoc generate anything when you don't install this plugin? I wonder because context.project.children shouldnt be undefined.

eshcharc commented 4 years ago

Yes. Just tried, and a docs folder was created with the main README.md showing

eshcharc commented 4 years ago

Tried a clean typedoc within one of the packages and it generated docs as well

marcj commented 4 years ago

Please try typedoc 0.16.8 and please also try typedoc.js, that's the way I use it

eshcharc commented 4 years ago

Well, I couldn't make it work with either of the configuration files (typedoc 0.16.8), but surprisingly, it did work when options were set from the CLI with flags. Not my ideal solution, but at least it works.

Thank you for the feedback, and if you have any idea of why it happens, I'll be glad to hear.

marcj commented 4 years ago

Feel free to post a github repo I can use to reproduce. Maybe it's a windows issue.

eshcharc commented 4 years ago

I'm quite embarrassed to say, I ran it without mentioning the source files ('packages' folder). Sorry for wasting your time. This issue can be closed now. Thanks for your help anyways.

rafaelmelon commented 4 years ago

Similar error here with (typedoc 0.16.8 and typedoc-plugin-lerna-packages 0.3.0):

Using TypeScript 3.7.5 from /monorepo/node_modules/typedoc/node_modules/typescript/lib
/monorepo/node_modules/typedoc/node_modules/typescript/lib/typescript.js:34103
            if (symbol.flags & 33554432 /* Transient */)
                       ^

TypeError: Cannot read property 'flags' of undefined
    at getSymbolLinks (/monorepo/node_modules/typedoc/node_modules/typescript/lib/typescript.js:34103:24)
    at getExportsOfModule (/monorepo/node_modules/typedoc/node_modules/typescript/lib/typescript.js:35607:25)
    at Object.getExportsOfModuleAsArray [as getExportsOfModule] (/monorepo/node_modules/typedoc/node_modules/typescript/lib/typescript.js:35573:35)
    at ExportDeclarationConverter.convert (/monorepo/node_modules/typedoc/dist/lib/converter/nodes/export.js:86:50)
    at Converter.convertNode (/monorepo/node_modules/typedoc/dist/lib/converter/converter.js:116:53)
    at /monorepo/node_modules/typedoc/dist/lib/converter/nodes/block.js:65:28
    at Array.forEach (<anonymous>)
    at BlockConverter.convertStatements (/monorepo/node_modules/typedoc/dist/lib/converter/nodes/block.js:64:24)
    at /monorepo/node_modules/typedoc/dist/lib/converter/nodes/block.js:43:26
    at Context.withScope (/monorepo/node_modules/typedoc/dist/lib/converter/context.js:101:9)
dariusrosendahl commented 4 years ago

@eshcharc How did you fix it? I have the exact same problem.

I tried to call it with the CLI like this:

typedoc --out ./docs ./packages

Output:

Loaded plugin /path/to/node_modules/typedoc-plugin-lerna-packages

Using TypeScript 3.8.3 from /usr/local/lib/node_modules/typescript/lib
Lerna packages found {
  '@testproject/testproject-core': 'packages/testproject-core',
  '@testproject/testproject-core-ui': 'packages/testproject-core-ui',
  '@testproject/testproject-content-data': 'packages/testproject-content-data',
  '@testproject/testproject-content': 'packages/testproject-content',
  '@testproject/testproject-commerce-data': 'packages/testproject-commerce-data',
  '@testproject/testproject-commerce': 'packages/testproject-commerce',
  '@testproject/create-testproject': 'packages/testproject-create',
  '@testproject/testproject-pwa': 'packages/testproject-pwa'
}
/path/to/node_modules/typedoc-plugin-lerna-packages/dist/plugin.js:58
        const copyChildren = context.project.children.slice(0);
                                                      ^

TypeError: Cannot read property 'slice' of undefined
    at LernaPackagesPlugin.onBeginResolve (/path/to/node_modules/typedoc-plugin-lerna-packages/dist/plugin.js:58:55)
    at triggerEvents (/usr/local/lib/node_modules/typedoc/dist/lib/utils/events.js:128:43)
    at triggerApi (/usr/local/lib/node_modules/typedoc/dist/lib/utils/events.js:110:13)
    at eventsApi (/usr/local/lib/node_modules/typedoc/dist/lib/utils/events.js:21:18)
    at Converter.trigger (/usr/local/lib/node_modules/typedoc/dist/lib/utils/events.js:264:13)
    at Converter.resolve (/usr/local/lib/node_modules/typedoc/dist/lib/converter/converter.js:164:14)
    at Converter.convert (/usr/local/lib/node_modules/typedoc/dist/lib/converter/converter.js:91:30)
    at CliApplication.convert (/usr/local/lib/node_modules/typedoc/dist/lib/application.js:70:39)
    at CliApplication.bootstrap (/usr/local/lib/node_modules/typedoc/dist/lib/cli.js:45:34)
    at Object.<anonymous> (/usr/local/lib/node_modules/typedoc/bin/typedoc:5:5)
eshcharc commented 4 years ago

Nope. I thought it was okay, but now I see that it still exists. I tried to debug the plugin, but came up with nothing. I left it in favor of other things, but I'll be happy if that is solved.

eshcharc commented 4 years ago

It seems that the plugin / typedoc doesn't like the wildcard sign (*) when mentioning lerna packages (e.g. in inputFiles option). IMO, that's the cause for the slice of undefined error. Workaround this is to explicitly name the packages of your project. I've managed to enable it all (not before encountering the flags error), and I might upload a sample project for you to examine later today.

dariusrosendahl commented 4 years ago

I got it working with the exact versions from the readme and using npx typedoc instead of npm run typedoc (that was using the project version of typescript). Still seems this project needs an upgrade to be able to use typescript version 3.8.*

chentsulin commented 4 years ago

@marcj @eshcharc @dariusrosendahl

Actually, context.project.children could be undefined in some cases. After I patched this line in my node_module, it works.

typedoc: 0.17 typescript: 3.9

See: https://github.com/marcj/typedoc-plugin-lerna-packages/pull/23#issue-441353374