Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to error message for incompatible tsconfigs #532

Closed
renewooller opened this issue Feb 13, 2018 · 4 comments
Closed

Improvements to error message for incompatible tsconfigs #532

renewooller opened this issue Feb 13, 2018 · 4 comments

Comments

@renewooller
Copy link

renewooller commented Feb 13, 2018

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.

@blakeembrey
Copy link
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.

@renewooller
Copy link
Author

renewooller commented Feb 19, 2018

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.

@blakeembrey
Copy link
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.

@blakeembrey
Copy link
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
Projects
None yet
Development

No branches or pull requests

2 participants