Skip to content

[BUG] SyntaxError: JSON5: invalid character '.' at 1:470 #1124

Closed

Description

@taras-kravets-ua

Error during generation of routes JSON file, maybe a trailing comma or an external variable inside one route.

Unhandled Rejection at: Promise {
SyntaxError: JSON5: invalid character '.' at 1:470
at syntaxError (/Users/project/node_modules/json5/lib/parse.js:1083:17)
at invalidChar (/Users/project/node_modules/json5/lib/parse.js:1028:12)
at Object.afterArrayValue (/Users/project/node_modules/json5/lib/parse.js:672:15)
at Object.default (/Users/project/node_modules/json5/lib/parse.js:146:37)
at lex (/Users/project/node_modules/json5/lib/parse.js:78:42)
at Object.parse (/Users/project/node_modules/json5/lib/parse.js:25:17)
at loopModulesParser (/Users/project/node_modules/@compodoc/compodoc/dist/index-cli-32a621dc.js:5711:51)
at RouterParserUtil.constructRoutesTree (/Users/project/node_modules/@compodoc/compodoc/dist/index-cli-32a621dc.js:5736:13)
at AngularDependencies.getDependencies (/Users/project/node_modules/@compodoc/compodoc/dist/index-cli-32a621dc.js:8673:50)
at CliApplication.Application.getDependenciesData (/Users/project/node_modules/@compodoc/compodoc/dist/index-cli-32a621dc.js:10227:40) {
lineNumber: 1,
columnNumber: 470
}
}

Angular CLI: 12.1.2
Node: 14.17.6
Package Manager: npm 6.14.15
OS: darwin x64
Compodoc: 1.1.14

Activity

  1. MysticBlaze085 commented on Oct 5, 2021

    @MysticBlaze085

    I am currently running into this error which is keeping me from using storybook

  2. changed the title [-]SyntaxError: JSON5: invalid character '.' at 1:470[/-] [+][BUG] SyntaxError: JSON5: invalid character '.' at 1:470[/+] on Dec 29, 2021
  3. luizfernando1996 commented on Feb 16, 2022

    @luizfernando1996

    +1

  4. raghav-kanwal commented on Feb 18, 2022

    @raghav-kanwal

    +1. Getting this issue which is blocking me from using Storybook with Angular as well.

  5. AliF50 commented on Feb 22, 2022

    @AliF50

    How I unblocked myself with regards to this error:

    I ctrl + clicked on the parse.js:1083:17 error in the terminal (in VS Code, it should open up the file) and I was presented with a function that's similar to this:

    parse js

    I added the console.log (shown in picture) of line, column, parseState, stack, pos, token, key and root, saved the file, and re-ran the command. For me the root property gave me a hint as to which one of my files was causing the issue. It turns out I was using spread syntax (...) in route configuration file and although Angular was not complaining about it, compodoc did not like it. I rewrote the spread syntax into something else and compodoc was satisfied with that and the error did not appear anymore.

    Unless if I missed it, I think it would be good if Compodoc can show in red bold text which file was scanned and caused the error.

  6. vogloblinsky commented on Feb 22, 2022

    @vogloblinsky
    Contributor

    @AliF50 Do you have an example of your spread syntax please ?

  7. AliF50 commented on Feb 22, 2022

    @AliF50

    I think it was something like this:

    const routes = [{ path: 'abc', component: ComponentA, }, { path: 'def', loadChildren: async () => (await import('./path/componentB')).ComponentBModule, }].map(route => ({ ...route, ...(route.component && canActivate: [FeatureGuard]), ...(route.loadChildren && canLoad: [FeatureGuard]), }));

    I am going off of memory but I am pretty sure it was like so. I just attached the respective canActivate and canLoad for every entry and removed the map to fix it.

    The code might not be formatted the best (final display) but I formatted it well in my comment. We are using compodoc ^1.1.11.

    Edit: I was able to reproduce it with the following.
    parse(2) js

  8. rasmus-e-christensen commented on Mar 2, 2022

    @rasmus-e-christensen

    It seems to be something to do with the "..." notation that is causing trouble, in my case at least :) I want to use on a big project and can only use the minimal use of compodoc, which is helpful but not that much.

  9. syndesis commented on Mar 10, 2022

    @syndesis

    I'm seeing it break in a similar way on a route like this:

              {
                path: 'foo',
                canActivate: [AuthenticationGuard, FeatureFlagGuard],
                loadChildren: (): Promise<RouterModule> =>
                  import('foo').then((m) => m.FeatureFooModule),
                data: {
                  title: { name: 'Foo' },
                  preload: true,
                  featureFlagKey: FeatureFlags.FOO_FLAG,
                  relativePathToRedirect: '..',
                },
              },

    it dies on the . in FeatureFlags.FOO_FLAG

    This may be related to json5/json5#249

  10. admir86 commented on Mar 21, 2022

    @admir86

    same problem when using TimeUserEntry.JOB_DESIGNATION direct in the userEntries. Using TimeUserEntry.JOB_DESIGNATION via a const works

    const JD = TimeUserEntry.JOB_DESIGNATION;
    const routes: Routes = [
      {
        path: '',
        component: TimeComponent,
        children: [
          {
            path: ROUTES.EMPLOYMENTS,
            loadChildren: () => import('@inova/basiskomponenten').then((m) => m.UserEntryModule),
            data: {
              userEntries: [JD],
            },
          },
          { path: ROUTES.CONFIGURATION, loadChildren: () => import('@inova/basiskomponenten').then((m) => m.DomainConfigurationModule) },
        ],
      },
    ];
  11. stale commented on Jul 10, 2022

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  12. divyeshjethwa commented on Jul 21, 2022

    @divyeshjethwa

    How I unblocked myself with regards to this error:

    I ctrl + clicked on the parse.js:1083:17 error in the terminal (in VS Code, it should open up the file) and I was presented with a function that's similar to this:

    parse js

    I added the console.log (shown in picture) of line, column, parseState, stack, pos, token, key and root, saved the file, and re-ran the command. For me the root property gave me a hint as to which one of my files was causing the issue. It turns out I was using spread syntax (...) in route configuration file and although Angular was not complaining about it, compodoc did not like it. I rewrote the spread syntax into something else and compodoc was satisfied with that and the error did not appear anymore.

    Unless if I missed it, I think it would be good if Compodoc can show in red bold text which file was scanned and caused the error.

    I followed your steps the same way. Added console.log in the parse.js and it pointed out what was causing the problem
    You rock

  13. stale commented on Jul 31, 2022

    @stale

    This issue has been automatically closed because it has not had recent activity. Please file a new issue if you are encountering a similar or related problem. Thank you for your contributions.

  14. spyro2000 commented on Aug 2, 2022

    @spyro2000

    Still same problem with 1.1.19.

    In routes:

    Explodes:

    {
            path: 'my-component',
            component: MyComponent,
            data: { propertyName: MyEnum.myValue},
     },

    Runs:

    {
            path: 'my-component',
            component: MyComponent,
            data: { propertyName: 'myValue'},
     },

    Did only find that out by debugging the json builder.

  15. ElfenB commented on Sep 1, 2022

    @ElfenB

    This is also an issue for me. I can temporarily fix it by removing the '.' within the require statement but I wouldn't consider this a fix because of course I have to change it after every new npm install ...

    parse.js

    // before
    const util = require('./util')
    // after
    const util = require('util')

    terminal output (excerpt)

    reason: SyntaxError: JSON5: invalid character '.' at 1:40
        at syntaxError (C:\_projects\my-project\node_modules\json5\lib\parse.js:1083:17)
  16. Nathanrs15 commented on Nov 16, 2022

    @Nathanrs15

    How I unblocked myself with regards to this error:

    I ctrl + clicked on the parse.js:1083:17 error in the terminal (in VS Code, it should open up the file) and I was presented with a function that's similar to this:

    parse js

    I added the console.log (shown in picture) of line, column, parseState, stack, pos, token, key and root, saved the file, and re-ran the command. For me the root property gave me a hint as to which one of my files was causing the issue. It turns out I was using spread syntax (...) in route configuration file and although Angular was not complaining about it, compodoc did not like it. I rewrote the spread syntax into something else and compodoc was satisfied with that and the error did not appear anymore.

    Unless if I missed it, I think it would be good if Compodoc can show in red bold text which file was scanned and caused the error.

    This worked for me. I found that it complains about a resolver class:

    ❌ Bad:

    {path: 'some-path', resolver: { ResolverClass } ...}

    👍 Good:

    {path: 'some-path', resolver: { name: ResolverClass } ...}

  17. ivanFlor3s commented on Apr 26, 2023

    @ivanFlor3s

    This is also an issue for me. I can temporarily fix it by removing the '.' within the require statement but I wouldn't consider this a fix because of course I have to change it after every new npm install ...

    parse.js

    // before
    const util = require('./util')
    // after
    const util = require('util')

    terminal output (excerpt)

    reason: SyntaxError: JSON5: invalid character '.' at 1:40
        at syntaxError (C:\_projects\my-project\node_modules\json5\lib\parse.js:1083:17)

    It solved my problem when generating documentation

  18. enrosales commented on May 24, 2023

    @enrosales
    error in compodoc

    in my case doing this and setting clg() in the syntaxError function fix the problem

  19. markwhitfeld commented on Jun 25, 2025

    @markwhitfeld

    @AliF50's approach of adding the console log helped me identify the issue.
    For anyone that would like to copy paste the console log, here it is:

    console.log({line, column, parseState, stack, pos, token, key, root})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions