question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] "TypeError: Cannot read property 'text' of undefined" with generating documentation with routes graph

See original GitHub issue
Overview of the issue

Documentation generation failing with error like below during documentation generation on routing module file when there are too many (?) thing exported from file with the routing module.

[10:33:56] Analysing routes definitions and clean them if necessary Unhandled Rejection at: Promise { <rejected> TypeError: Cannot read property 'text' of undefined at E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:1397:55 at Function.ArrayUtils.find (E:\Projects\someFolder\rwd\node_modules\ts-simple-ast\dist\utils\ArrayUtils.js:37:21) at Object.getNodeByNameOrFindFunction (E:\Projects\someFolder\rwd\node_modules\ts-simple-ast\dist\utils\compiler\getNodeByNameOrFindFunction.js:10:36) at SourceFile.StatementedNode.class_1.getVariableDeclaration (E:\Projects\someFolder\rwd\node_modules\ts-simple-ast\dist\compiler\statement\StatementedNode.js:312:28) at RouterParserUtil.cleanCallExpressions (E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:1394:45) at Dependencies.getSourceFileDecorators (E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:5811:45) at E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:5638:27 at Array.map (<anonymous>) at Dependencies.getDependencies (E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:5632:21) at CliApplication.Application.getDependenciesData (E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:7309:40) } reason: TypeError: Cannot read property 'text' of undefined at E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:1397:55 at Function.ArrayUtils.find (E:\Projects\someFolder\rwd\node_modules\ts-simple-ast\dist\utils\ArrayUtils.js:37:21) at Object.getNodeByNameOrFindFunction (E:\Projects\someFolder\rwd\node_modules\ts-simple-ast\dist\utils\compiler\getNodeByNameOrFindFunction.js:10:36) at SourceFile.StatementedNode.class_1.getVariableDeclaration (E:\Projects\someFolder\rwd\node_modules\ts-simple-ast\dist\compiler\statement\StatementedNode.js:312:28) at RouterParserUtil.cleanCallExpressions (E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:1394:45) at Dependencies.getSourceFileDecorators (E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:5811:45) at E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:5638:27 at Array.map (<anonymous>) at Dependencies.getDependencies (E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:5632:21) at CliApplication.Application.getDependenciesData (E:\Projects\someFolder\rwd\node_modules\@compodoc\compodoc\dist\index-cli.js:7309:40)

File on which generation works:

import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";

import { ErrorPageComponent } from "./error-page.component";

export const errorRoutes: Routes = [
  {
    path: "error",
    component: ErrorPageComponent
  }
];

@NgModule({
  imports: [
    RouterModule.forChild(errorRoutes)
  ]
})
export class ErrorRoutingModule {
}

File on which generation fails:

import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";

import { ErrorPageComponent } from "./error-page.component";

export const SOMETHING: string = "aaa";

export const errorRoutes: Routes = [
  {
    path: "error",
    component: ErrorPageComponent
  }
];

@NgModule({
  imports: [
    RouterModule.forChild(errorRoutes)
  ]
})
export class ErrorRoutingModule {
}
Operating System, Node.js, npm, compodoc version(s)
  • Windows 8.1
  • NodeJs - 8.10.0
  • npm 5.7.1
  • compodoc 1.1.3
Angular configuration, a package.json file in the root folder

As we have quite complex tree-structured projects isn’t is actual content, but most important parts of merged configurations:

{
  "author": "XXX",
  "name": "xxx",
  "version": "0.0.1",
  "dependencies": {
    "@angular/animations": "5.2.*",
    "@angular/common": "5.2.*",
    "@angular/compiler": "5.2.*",
    "@angular/core": "5.2.*",
    "@angular/forms": "5.2.*",
    "@angular/http": "5.2.*",
    "@angular/platform-browser": "5.2.*",
    "@angular/platform-browser-dynamic": "5.2.*",
    "@angular/router": "5.2.*",
    "@ngrx/effects": "5.0.*",
    "@ngrx/router-store": "5.0.*",
    "@ngrx/store": "5.0.*",
    "@ngx-translate/core": "9.1.*",
    "core-js": "2.5.*",
    "lodash": "4.17.*",
    "moment": "2.20.*",
    "ng2-markdown-to-html": "1.3.*",
    "ng2-nouislider": "1.7.*",
    "ngrx-store-localstorage": "5.0.*",
    "normalize.css": "7.0.*",
    "primeng": "5.2.*",
    "prismjs": "1.14.*",
    "rxjs": "5.5.*",
    "zone.js": "0.8.*"
  },
  "devDependencies": {
    "@angular/compiler-cli": "5.2.*",
    "@angular/language-service": "5.2.*",
    "@compodoc/compodoc": "1.1.*",
    "@ngrx/store-devtools": "4.1.*",
    "@ngtools/webpack": "1.10.*",
    "@types/file-saver": "^1.3.0",
    "@types/jasmine": "2.8.*",
    "@types/jasmine-expect": "3.6.*",
    "@types/jasminewd2": "2.0.*",
    "@types/karma": "1.7.*",
    "@types/lodash": "4.14.104",
    "@types/node": "6.*.*",
    "@types/run-sequence": "0.0.*",
    "@types/webpack": "3.8.*",
    "@types/webpack-env": "1.13.*",
    "angular2-template-loader": "0.6.*",
    "awesome-typescript-loader": "3.4.*",
    "codecov": "3.0.*",
    "codelyzer": "4.3.*",
    "compare-json": "0.3.*",
    "concurrently": "3.5.*",
    "copy": "0.3.2",
    "copy-webpack-plugin": "4.1.*",
    "css-loader": "0.28.*",
    "css-hot-loader": "1.3.*",
    "extract-text-webpack-plugin": "3.0.*",
    "file-loader": "1.1.*",
    "html-webpack-plugin": "3.0.*",
    "istanbul-instrumenter-loader": "3.0.*",
    "jasmine-core": "2.8.*",
    "jasmine-marbles": "0.2.*",
    "jasmine-spec-reporter": "4.2.*",
    "json-loader": "0.5.*",
    "karma": "2.0.*",
    "karma-chrome-launcher": "2.2.*",
    "karma-cli": "1.0.*",
    "karma-coverage-istanbul-reporter": "1.4.*",
    "karma-firefox-launcher": "1.0.*",
    "karma-jasmine": "1.1.*",
    "karma-jasmine-html-reporter": "0.2.*",
    "karma-jasmine-matchers": "3.7.*",
    "karma-junit-reporter": "1.2.*",
    "karma-mocha-reporter": "2.2.*",
    "karma-phantomjs-launcher": "1.0.*",
    "karma-remap-coverage": "0.1.*",
    "karma-sourcemap-loader": "0.3.*",
    "karma-webpack": "2.0.*",
    "lite-server": "2.3.*",
    "ngrx-store-freeze": "0.2.*",
    "node-sass": "4.7.*",
    "phantomjs-prebuilt": "2.1.*",
    "postcss": "6.0.*",
    "postcss-loader": "2.1.*",
    "protractor": "5.3.*",
    "raw-loader": "0.5.*",
    "run-sequence": "2.2.*",
    "sass-loader": "6.0.*",
    "source-map-explorer": "1.5.*",
    "source-map-loader": "0.2.*",
    "to-string-loader": "1.1.*",
    "tslint": "5.10.*",
    "tslint-consistent-codestyle": "1.13.*",
    "tslint-language-service": "0.9.*",
    "typescript": "2.5.*",
    "uglifyjs-webpack-plugin": "1.1.*",
    "webpack": "3.11.*",
    "webpack-dev-server": "2.11.*",
    "webpack-node-externals": "1.6.*"
  },
  "engines": {
    "node": ">=6.9.0 <9.0.0",
    "npm": ">=3.10.3 <6.0.0"
  }
}
Compodoc installed globally or locally ?

Locally

Motivation for or Use Case

Can’t create a documentation with routing graph.

Reproduce the error

Sample files presented in first part of the bug report.

Related issues

Maybe #427

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

1reaction
stevewithingtoncommented, May 3, 2019

@nixallover, was scratching my head on this one until coming across your solution. Perfect!

I was reading in some environment settings for useHash and enableTracing. Errors out when using a const, but works fine when returning from a function.

Fail 👎

import { environment } from '../environments/environment';

const envUseHash: boolean = environment.ROUTES_USE_HASH;
const envEnableTracing: boolean = environment.ENABLE_TRACING;

const APP_ROUTES: Routes = [
 // my routes ...
];

@NgModule({
  imports: [
    RouterModule.forRoot(
      APP_ROUTES,
      {
        useHash: envUseHash ,
        enableTracing: envEnableTracing
      }
    ),
  ]
})
export class AppRoutingModule {}

Pass 👍

import { environment } from '../environments/environment';

function getEnableTracing(): boolean {
  return environment.ENABLE_TRACING;
}

function getUseHash(): boolean {
  return environment.ROUTES_USE_HASH;
}

const APP_ROUTES: Routes = [
 // my routes ...
];

@NgModule({
  imports: [
    RouterModule.forRoot(
      APP_ROUTES,
      {
        useHash: getUseHash(),
        enableTracing: getEnableTracing()
      }
    ),
  ]
})
export class AppRoutingModule {}
1reaction
nixallovercommented, Feb 1, 2019

@mkp05 Thanks so much for posting this! You helped me find a solution for my project. I had a const that held some shared static text that was being passed into some of my routes as title data. I fixed the issue by changing that const string to a function that returns a string.

Before (produces error):

const description = 'Another fancy page';

const routes: Routes = [
    {
        path: 'fancy',
        component: FancyComponent,
        data: {
            routeTitle: 'Fancy',
            routeDescription: description
        }
    },
    ...
];

After (error-free):

function description() {
    return 'Another fancy page';
}

const routes: Routes = [
    {
        path: 'fancy',
        component: FancyComponent,
        data: {
            routeTitle: 'Fancy',
            routeDescription: description()
        }
    },
    ...
];
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I fix "Cannot read property 'document' of undefined ...
One way to fix this issue is to use the dynamic import of nextjs import dynamic from 'next/dynamic' const Chart = dynamic(() ...
Read more >
Node.js v19.3.0 Documentation
If the message parameter is undefined, a default error message is assigned. ... the TypeError because there is no matching error type in...
Read more >
How to Read React Errors (fix 'Cannot read property of ...
TypeError is the kind of error. There are a handful of built-in error types. · Cannot read property means the code was trying...
Read more >
Cannot read properties of undefined (reading 'length') - TrackJS
This message indicates that our code expects to have an object with a length property, but that object was not present.
Read more >
Cannot read property scope of undefined - Treehouse
I'm getting an error when I run this project. Here is the stack trace.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found