compodoc: [BUG] Cannot generate documentation of a lazy loaded Angular app

Overview of the issue

Whenever I try to generate the documentation, I receive this error: reason: Error: Could not find the node's symbol. I saw this error has been filed several times, it should be assessed to be honest.

Operating System, Node.js, npm, compodoc version(s)

OS: MacOS Node.js: 12.13.0 npm: 6.13.7 compodoc: 1.1.11

Angular configuration, a package.json file in the root folder
{
  "name": "PRIVATE",
  "version": "PRIVATE",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "test_cc": "ng test --code-coverage --source-map",
    "lint": "ng lint",
    "serve": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng serve --prod",
    "build_prod": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng build --prod",
    "commit:init": "git config --local commit.template ./tools/.git-commit-template.txt",
    "compodoc": "npx compodoc -p ./tsconfig.json"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.2.4",
    "@angular/cdk": "^8.1.4",
    "@angular/common": "^8.2.4",
    "@angular/compiler": "^8.2.4",
    "@angular/core": "^8.2.4",
    "@angular/forms": "^8.2.4",
    "@angular/material": "^8.1.4",
    "@angular/material-moment-adapter": "^8.1.4",
    "@angular/platform-browser": "^8.2.4",
    "@angular/platform-browser-dynamic": "^8.2.4",
    "@angular/pwa": "^0.803.9",
    "@angular/router": "^8.2.4",
    "@angular/service-worker": "^8.2.4",
    "@auth0/angular-jwt": "^2.1.2",
    "@ngrx/core": "^1.2.0",
    "@ngrx/effects": "^6.1.2",
    "@ngx-translate/core": "^10.0.2",
    "@ngx-translate/http-loader": "^3.0.1",
    "@swimlane/ngx-charts": "^12.0.1",
    "@swimlane/ngx-graph": "^6.1.0",
    "@turf/turf": "^5.1.6",
    "@types/jspdf": "^1.3.1",
    "angular-tree-component": "8.5.2",
    "core-js": "^2.6.9",
    "d3": "^5.11.0",
    "dexie": "^2.0.4",
    "fabric": "^3.4.0",
    "html2canvas": "^1.0.0-rc.3",
    "intl": "^1.2.5",
    "jquery": "^3.4.1",
    "jspdf": "^1.5.3",
    "moment": "^2.24.0",
    "ng2-dragula": "^2.1.1",
    "ngx-device-detector": "^1.3.19",
    "ngx-papaparse": "^4.0.4",
    "ngx-summernote": "^0.5.5",
    "ngx-toastr": "^9.2.0",
    "ngx-translate-multi-http-loader": "^3.0.0",
    "ngx-tui-image-editor": "^7.0.2",
    "ol": "^5.3.3",
    "rxjs": "^6.5.2",
    "snazzy-info-window": "^1.1.1",
    "stream": "0.0.2",
    "summernote": "^0.8.12",
    "timers": "^0.1.1",
    "tslib": "^1.10.0",
    "tui-image-editor": "^3.7.0",
    "xml-js": "^1.6.11",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.800.6",
    "@angular/cli": "~8.0.6",
    "@angular/compiler-cli": "^8.2.4",
    "@angular/language-service": "^8.2.4",
    "@types/jasmine": "^2.8.16",
    "@types/jasminewd2": "^2.0.6",
    "@types/node": "^8.10.53",
    "acorn": "^6.3.0",
    "angular-tslint-rules": "^1.18.0",
    "codelyzer": "^5.0.1",
    "commitizen": "^4.0.3",
    "git-branch": "^2.0.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^3.1.4",
    "karma-chrome-launcher": "^2.2.0",
    "karma-coverage-istanbul-reporter": "^2.0.6",
    "karma-jasmine": "~1.1.1",
    "karma-jasmine-html-reporter": "^0.2.2",
    "parcel-bundler": "^1.12.3",
    "shallow-render": "^8.2.1",
    "ts-loader": "6.2.1",
    "ts-node": "~5.0.1",
    "tslint": "^5.19.0",
    "tslint-config-airbnb": "^5.11.1",
    "typescript": "~3.4.5"
  },
  "config": {
    "commitizen": {
      "path": "./tools/.cz-config.js"
    }
  }
}

Compodoc installed globally or locally ?

globally

If possible sourcecode of the file where it breaks

All my *-routing.module.ts

If possible your terminal logs before the error
Unhandled Rejection at: Promise {
  <rejected> InvalidOperationError: Could not find the node's symbol.
      at InvalidOperationError.BaseError [as constructor] (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/node_modules/ts-simple-ast/dist/errors/BaseError.js:7:28)
      at new InvalidOperationError (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/node_modules/ts-simple-ast/dist/errors/InvalidOperationError.js:8:28)
      at Object.throwIfNullOrUndefined (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/node_modules/ts-simple-ast/dist/errors/helpers.js:96:15)
      at Identifier.Node.getSymbolOrThrow (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/node_modules/ts-simple-ast/dist/compiler/common/Node.js:131:23)
      at RouterParserUtil.cleanFileDynamics (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/dist/application-54cd2170.js:5668:18)
      at AngularDependencies.getSourceFileDecorators (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/dist/application-54cd2170.js:8152:46)
      at /Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/dist/application-54cd2170.js:7960:31
      at Array.map (<anonymous>)
      at AngularDependencies.getDependencies (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/dist/application-54cd2170.js:7949:21)
      at CliApplication.Application.getDependenciesData (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/dist/application-54cd2170.js:9498:40)
} reason: InvalidOperationError: Could not find the node's symbol.
    at InvalidOperationError.BaseError [as constructor] (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/node_modules/ts-simple-ast/dist/errors/BaseError.js:7:28)
    at new InvalidOperationError (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/node_modules/ts-simple-ast/dist/errors/InvalidOperationError.js:8:28)
    at Object.throwIfNullOrUndefined (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/node_modules/ts-simple-ast/dist/errors/helpers.js:96:15)
    at Identifier.Node.getSymbolOrThrow (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/node_modules/ts-simple-ast/dist/compiler/common/Node.js:131:23)
    at RouterParserUtil.cleanFileDynamics (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/dist/application-54cd2170.js:5668:18)
    at AngularDependencies.getSourceFileDecorators (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/dist/application-54cd2170.js:8152:46)
    at /Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/dist/application-54cd2170.js:7960:31
    at Array.map (<anonymous>)
    at AngularDependencies.getDependencies (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/dist/application-54cd2170.js:7949:21)
    at CliApplication.Application.getDependenciesData (/Users/dimitrirodriguesoliveira/.nvm/versions/node/v12.13.0/lib/node_modules/@compodoc/compodoc/dist/application-54cd2170.js:9498:40)
[12:16:13] Sorry, but there was a problem during parsing or generation of the documentation. Please fill an issue on github. (https://github.com/compodoc/compodoc/issues/new)
Motivation for or Use Case

Cannot generate the documentation

Reproduce the error

Use compodoc on any complex lazy-loading app

Related issues

Yes, many that are flagged as wontfix

Suggest a Fix

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 11
  • Comments: 21 (1 by maintainers)

Most upvoted comments

Compodoc does not understand lazy loading when written with an arrow function with parentheses (m) => m.MyModule.

  1. open node_modules/@compodoc/compodoc/dist/application-54cd2170.js
  2. look at row 5129
  3. replace
    /(['"]loadChildren['"]:)\(\)=>"import\((\\'|'|")([^'"]+?)(\\'|'|")\)\.then\(\w+?=>\S+?\.([^)]+?)\)(\\'|'|")/g;
    to
    /(['"]loadChildren['"]:)\(\)=>"import\((\\'|'|")([^'"]+?)(\\'|'|")\)\.then\(\(?\w+?\)?=>\S+?\.([^)]+?)\)(\\'|'|")/g;

the solution from @iamruslanbakirov works for me. Yet I don’t even know why.

The compodoc generator fails when using Routes (which is Angulars default route syntax) instead of Route[], greeting you with the following error.

[12:22:59] Analysing routes definitions and clean them if necessary
Unhandled Rejection at: Promise {
  <rejected> InvalidOperationError: Could not find the node's symbol.

What’s confusing about this is that in Angulars source code, Routes itself is simply: export declare type Routes = Route[]; (an array of Route-Objects)

However: Replacing all const routes: Routes with const routes: Route[] in all of your *-routing.module.ts files does the trick.

To me it looks like some serious bugs in compodoc. That all related issues are marked with wontfix makes this tool even more frustrating.

Fixed for (m) => m.MyModulesyntax in 1.1.14 coming soon

It’s doesn’t work. if u open documentation, “Routing” section not show

at least the documentation was generated at all. With using Routes instead of Route[] not even the generator finishes

I’ve replaced the Typing from :Routes to Route[] but now compodoc does not generae a routing digram.

Guys, check your routes definition.

I changed const routes: Routes = […] to const routes: Route[] = […], and it’s working.

I’m not sure if that’s related, but I’m experiencing a similar issue with lazy routed modules. The error message is different though.

Code

{
  matcher: productListingMatcher,
  data: {
    title: '{category} Site name',
  },
  resolve: {
    category: CategoryResolver,
  },
  runGuardsAndResolvers: 'paramsOrQueryParamsChange',
  loadChildren: () => import('@/app/pages/product-listing/product-listing.module').then(m => m.ProductListingModule),
}

Error

(node:10583) UnhandledPromiseRejectionWarning: RangeError: Invalid array length...

I tried commenting out the loadChildren: ... part and everything seems to pass ok without it. I also tried using the relative path instead of alias in the import src, but that didn’t help.