Skip to content

[BUG] Using Enums in routes other than the main app-routing.module will throw an error in Compodoc build #1334

Closed

Description

@Offram
Overview of the issue

Using Enums in routes other than the main app-routing.module as shown below will throw an error in Compodoc build,
image

Unhandled Rejection at: Promise {
  <rejected> SyntaxError: JSON5: invalid character '.' at 1:282
      at syntaxError (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:1110:17)
      at invalidChar (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:1055:12)
      at Object.afterArrayValue (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:694:15)
      at Object.default (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:168:37)
      at lex (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:100:42)
      at Object.parse (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:25:17)
      at loopInsideModule (E:\Projects\Skeletons\angular-demo\node_modules\@compodoc\compodoc\dist\index-cli-f7393cac.js:6269:63)
      at loopRoutesParser (E:\Projects\Skeletons\angular-demo\node_modules\@compodoc\compodoc\dist\index-cli-f7393cac.js:6302:29)
      at loopRoutesParser (E:\Projects\Skeletons\angular-demo\node_modules\@compodoc\compodoc\dist\index-cli-f7393cac.js:6307:21)
      at RouterParserUtil.constructRoutesTree (E:\Projects\Skeletons\angular-demo\node_modules\@compodoc\compodoc\dist\index-cli-f7393cac.js:6311:9) {
    lineNumber: 1,
    columnNumber: 282
  }
} reason: SyntaxError: JSON5: invalid character '.' at 1:282
    at syntaxError (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:1110:17)
    at invalidChar (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:1055:12)
    at Object.afterArrayValue (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:694:15)
    at Object.default (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:168:37)
    at lex (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:100:42)
    at Object.parse (E:\Projects\Skeletons\angular-demo\node_modules\json5\lib\parse.js:25:17)
    at loopInsideModule (E:\Projects\Skeletons\angular-demo\node_modules\@compodoc\compodoc\dist\index-cli-f7393cac.js:6269:63)
    at loopRoutesParser (E:\Projects\Skeletons\angular-demo\node_modules\@compodoc\compodoc\dist\index-cli-f7393cac.js:6302:29)
    at loopRoutesParser (E:\Projects\Skeletons\angular-demo\node_modules\@compodoc\compodoc\dist\index-cli-f7393cac.js:6307:21)
    at RouterParserUtil.constructRoutesTree (E:\Projects\Skeletons\angular-demo\node_modules\@compodoc\compodoc\dist\index-cli-f7393cac.js:6311:9) {
  lineNumber: 1,
  columnNumber: 282
}
[17:50:21] 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)
Operating System, Node.js, npm, compodoc version(s)

OS : Windows 10
Node : v16.14.2
compodoc : 1.1.19

Angular configuration, a package.json file in the root folder
{
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "lint": "ng lint",
    "doc": "compodoc -p tsconfig.doc.json -w -s",
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^15.2.7",
    "@angular/common": "^15.2.7",
    "@angular/compiler": "^15.2.7",
    "@angular/core": "^15.2.7",
    "@angular/forms": "^15.2.7",
    "@angular/platform-browser": "^15.2.7",
    "@angular/platform-browser-dynamic": "^15.2.7",
    "@angular/router": "^15.2.7",
    "@angular/service-worker": "^15.2.7",
    "@ngneat/transloco": "^4.2.2",
    "tslib": "^2.3.0",
    "zone.js": "~0.12.0"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^15.2.6",
    "@angular-eslint/builder": "15.2.1",
    "@angular-eslint/eslint-plugin": "15.2.1",
    "@angular-eslint/eslint-plugin-template": "15.2.1",
    "@angular-eslint/schematics": "15.2.1",
    "@angular-eslint/template-parser": "15.2.1",
    "@angular/cli": "~15.2.6",
    "@angular/compiler-cli": "^15.2.7",
    "@angular/localize": "^15.2.7",
    "@compodoc/compodoc": "^1.1.19",
    "typescript": "~4.9.4"
  },
  "type": "module"
}
Compodoc installed globally or locally ?

Globally and locally

If possible sourcecode of the file where it breaks

test-comp-routing.module.ts file

  const routes: Routes = [{
    path: 'userType2', component: UserType2Component,
    canActivate: [RoleGuard],
    data: {
      allowedUserTypes: [
        UserTypes.UserType2
      ]
    }
  },]

UserTypes.enum.ts

export enum UserTypes {
  UserType1,
  UserType2,
  UserType3
}
If possible your terminal logs before the error
Motivation for or Use Case

Sending route permissions through rout configuration.

Reproduce the error

🤷

Related issues

#959

Suggest a Fix

Activity

  1. Offram commented on May 13, 2023

    @Offram
    Author

    Console log of stack :

     stack: [
        [ [Object], [Object], [Object] ],
        {
          path: 'userType2',
          component: 'UserType2Component',
          canActivate: [Array],
          data: [Object]
        },
        { allowedUserTypes: [Array] },
        [ 'UserTypes' ]
      ],
    
  2. mradcliffe commented on May 16, 2023

    @mradcliffe

    I can confirm this in 1.1.19 independently.

    As a workaround, but not a fix, if the data property is assigned a variable with the structured data in the example above, compodoc does not throw an error.

    Example:

    const userType2Data = {
      allowedUserTypes: [
        UserTypes.UserType2
      ]
    };
    const routes: Routes = [{
      path: 'userType2', component: UserType2Component,
      canActivate: [RoleGuard],
      data: userType2Data,
    }];
    
  3. added a commit that references this issue on May 24, 2026
    f465fce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions