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

CRA 3 fails to handle a trailing comma in tsconfig.json - TSC has no problem #6865

Closed
TomasHubelbauer opened this issue Apr 23, 2019 · 7 comments

Comments

@TomasHubelbauer
Copy link
Contributor

This is a bug report. To reproduce it, run npx create-react-app . --typescript and change the "jsx": "preserve" line to "jsx": "preserve",. This is with CRA3 and I don't think this happened in CRA2 because I kept my tsconfig.json the same while upgrading CRA from 2 to 3 and only now got the error. I think this is a CRA issue because running tsc -p . in the directory goes through with no problem.

@ianschmitz
Copy link
Contributor

Yeah you're definitely right that tsconfig.json supports it. We'll have to investigate this. Likely a JSON.parse() somewhere.

@iansu
Copy link
Contributor

iansu commented Apr 23, 2019

TypeScript also allows you to put comments in tsconfig.json which makes it not actually JSON. As far as I know they strip them before parsing the file so it's possible they are doing something similar with trailing commas.

@TomasHubelbauer
Copy link
Contributor Author

I think as long as a JSONC parser is used it should all go through because that's what TS is using I'd assume.

@heyimalex
Copy link
Contributor

Unfortunately it looks like typescript uses a hand-written parser. I traced it down to parseJsonText which is defined in src/compiler/parser.ts. Ahahaha.

If we're allowed to hook into the typescript package, it looks like they provide public access to their parse function.

@ianschmitz
Copy link
Contributor

For whomever investigates this, I recommend taking a look at https://github.com/Realytics/fork-ts-checker-webpack-plugin for similar logic. I did a few PRs there related to parsing tsconfig using the TypeScript API that may be helpful.

However be careful as some of their functions will actually mutate the config. May not be worth using TS API potentially.

@TomasHubelbauer
Copy link
Contributor Author

This might have been fixed by #7248? In which case can be closed. I see it deals with comments, not sure if it fixed the commas as well?

@heyimalex
Copy link
Contributor

@TomasHubelbauer You're absolutely right!

@lock lock bot locked and limited conversation to collaborators Dec 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants