ngd icon indicating copy to clipboard operation
ngd copied to clipboard

Plugin does not support tsconfig.json file with multi-line comments

Open ldeluigi opened this issue 5 years ago • 1 comments

Describe the bug When using "ngd" command inside the root folder of an Angular 10 project an exception is thrown:

[20:30:05] using tsconfig: C:\Users\_\tsconfig.json
internal/modules/cjs/loader.js:1238
    throw err;
    ^

SyntaxError: C:\Users\_\tsconfig.json: Unexpected token / in JSON at position 0
    at parse (<anonymous>)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:1235:22)
    at Module.load (internal/modules/cjs/loader.js:1050:32)
    at Function.Module._load (internal/modules/cjs/loader.js:938:14)
    at Module.require (internal/modules/cjs/loader.js:1090:19)
    at require (internal/modules/cjs/helpers.js:75:18)
    at Object.Application.run (C:\Users\_\AppData\Roaming\npm\node_modules\@compodoc\ngd-cli\dist\cli.js:54:25)    
    at Object.<anonymous> (C:\Users\_\AppData\Roaming\npm\node_modules\@compodoc\ngd-cli\dist\index.js:4:19)       
    at Module._compile (internal/modules/cjs/loader.js:1201:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1221:10)

To Reproduce Steps to reproduce the behavior:

  1. Create an Angular 10 project
  2. Run "ngd" in the same folder as the tsconfig.json

Expected behavior It should understand that the text included in /* */ is a comment and parse the file correctly.

Screenshots If needed, ask me.

Desktop:

  • OS: Windows 10
  • Version 2.1.0

Additional context Here is my tsconfig.json, generated by Angular CLI:

/*
  This is a "Solution Style" tsconfig.json file, and is used by editors and TypeScript’s language server to improve development experience.
  It is not intended to be used to perform a compilation.

  To learn more about this file see: https://angular.io/config/solution-tsconfig.
*/
{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.spec.json"
    }
]
}

ldeluigi avatar Nov 20 '20 19:11 ldeluigi

I would say you should avoid loading the solution style file here, even more as the spec files are probably irrelevant to the project's hierarchy.

That say, a tool for Angular should understand "Json with comment" file format, including comments of both style, trailing commas, and so on. Perhaps the project should use a better library for reading Json config files?

On my project, it fails with:

SyntaxError: C:\___\tsconfig.main.json: Unexpected token ] in JSON at position 252
    at parse (<anonymous>)
    at Object.Module._extensions..json (internal/modules/cjs/loader.js:1128:22)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:93:18)
    at Object.Application.run (C:\PrgFiles\nvm\v14.18.2\node_modules\@compodoc\ngd-cli\dist\cli.js:54:25)
    at Object.<anonymous> (C:\PrgFiles\nvm\v14.18.2\node_modules\@compodoc\ngd-cli\dist\index.js:4:19)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

FYI, This file includes a tsconfig.common.js file, which includes another file from node_modules (one of our own libraries), making hard to track where the issue is. Of course, these config files are perfectly OK for TypeScript.

PhiLhoSoft avatar Jun 27 '22 08:06 PhiLhoSoft