Skip to content

Improvements to error message for incompatible tsconfigs #532

Closed

Description

@renewooller

Hi, this is a fantastic project, thanks for it.

I have some feedback for small improvements that could substantially improve the initial experience when working with random tsconfigs

When the tsconfig.json is incompatible with ts-node, we currently get an error like so:

SyntaxError: Unexpected token ] in JSON at position 152
    at JSON.parse (<anonymous>)
    at parse (/usr/local/opt/nvm/versions/node/v8.5.0/lib/node_modules/ts-
...

What would be great is if a JSON-schema or similar was defined for the tsconfig, and the incoming tsconfig.json was validated against the schema first before attempting to use it, so the error would then be something like:

ValidationError: tsconfig.json cannot have "include" member

An example of a ts-node compatible tsconfig in the documentation would also be useful - perhaps this can be driven off the same json-schema.

Let me know if you agree and what techniques you prefer and point me to where the most suitable places to make the changes and I'll do a pull request.

All the best.

Activity

  1. blakeembrey commented on Feb 19, 2018

    @blakeembrey
    Member

    JSON schema would not tell you your JSON is invalid as you'd still need to parse it to validate. What exactly are you suggesting? The correct fix would be to use TypeScript to load the tsconfig.json file if that API is properly exposed.

  2. renewooller commented on Feb 19, 2018

    @renewooller
    Author

    It seems the problem is not that it's invalid JSON, but rather that the tsconfig has fields that cannot be processed by ts-node, like 'include'. IE I've found through trial and error that if I remove 'include', it will work. So I'm proposing we include some post-parsing validation into ts-node to make sure the tsconfig is acceptable. I'd prefer to use JSON schema to do this, but I'm ok with hardcoding it as well if that suits the coding style of the project.

  3. blakeembrey commented on Feb 19, 2018

    @blakeembrey
    Member

    As far as I know, that's not the case. Would you like to make an example that can reproduce your issue? If the JSON is valid, you won't have a syntax error, so I'm not quite sure I follow how you landed in this issue.

  4. blakeembrey commented on Feb 19, 2018

    @blakeembrey
    Member

    Should be fixed with #536. I bumped a minimum TypeScript version required and am now using the built in TypeScript parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions