Skip to content

tsconfig.json and jsconfig.json not allowing comments (parsed as pure JSON) #7195

Closed
@kdmadej

Description

@kdmadej

Is this a bug report?

Yes

Did you try recovering your dependencies?

Yes

Which terms did you search for in User Guide?

JSON, parse, jsconfig

Environment

Environment Info:

  System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
  Binaries:
    Node: 10.11.0 - ~/.nvm/versions/node/v10.11.0/bin/node
    Yarn: 1.16.0 - /usr/local/Cellar/yvm/3.3.0/shim/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.11.0/bin/npm
  Browsers:
    Chrome: 74.0.3729.169
    Firefox: Not Found
    Safari: 12.1.1
  npmPackages:
    react: ^16.8.0 => 16.8.6 
    react-dom: ^16.8.0 => 16.8.6 
    react-scripts: ^3.0.1 => 3.0.1 
  npmGlobalPackages:
    create-react-app: Not Found

Steps to Reproduce

  1. create an initial app
  2. add jsconfig.json or tsconfig.json
  3. use a comment or leave a trailing comma in an array or an object

Expected Behavior

Since VSCode treats both tsconfig.json and jsconfig.json as JSON with Comments by default, it does not report any issues when adding comments or leaving trailing commas inside those files. As such I would expect the files to be parsed correctly and comments to be allowed.

Actual Behavior

The build fails as the aforementioned additions, which is to be expected if the files are treaded as pure JSON. The following output is produced when comments are present in the config:

yarn run v1.16.0
$ react-scripts build
internal/modules/cjs/loader.js:711
    throw err;
    ^

SyntaxError: /.../app/jsconfig.json: Unexpected token / in JSON at position 3
    at JSON.parse (<anonymous>)

Reproducible Demo

It should be fairly easy to quickly reproduce this issue in an empty create-react-app project.

Additional info

This issue is connected to #4763 although I believe this to be a bug. If this is indeed intended (I understand this is an issue with how cjs parses the files) I'd ask to at least have this behaviour mentioned in the documentation as it seems to diverge from the way that {ts,js}config.json files are treated by default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions