vite: [2.5 beta] json parse error for tsconfig.json that includes trailing comma in object
Describe the bug
the code reading tsconfig.json via tsconfig dependency that was added in this #4279 causes a json parse error if the tsconfig.json contains a trailing comma.
trailing commas and comments are allowed in tsconfig.json
also filed an upstream issue: https://github.com/TypeStrong/tsconfig/issues/30
Obvious workaround is to just remove the trailing comma, leaving this issue here anyways for visibility.
Reproduction
in any vite ts project linked to local vite with sufficient version
- add a trailing comma to tsconfig.json
- start dev
- parse error on cli
found via https://github.com/sveltejs/vite-plugin-svelte/blob/main/packages/e2e-tests/ts-type-import/
System Info
observed with local vite @ rev 69f91a1c03a129ab324c20fddfd2a07e729add96
Used Package Manager
pnpm
Logs
10:23:18 PM [vite] Internal server error: Unexpected token } in JSON at position 107
Plugin: vite:esbuild
File: /home/dominikg/develop/sveltejs/vite-plugin-svelte/packages/e2e-tests/ts-type-import/src/index.ts
at JSON.parse (<anonymous>)
at parse (/home/dominikg/develop/vite/node_modules/tsconfig/dist/tsconfig.js:135:17)
at /home/dominikg/develop/vite/node_modules/tsconfig/dist/tsconfig.js:116:32
at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:73:3)
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 16 (16 by maintainers)
Commits related to this issue
- fix: remove trailing comma from tsconfig.json. see https://github.com/vitejs/vite/issues/4481 — committed to sveltejs/vite-plugin-svelte by dominikg 3 years ago
- Fix/tsconfig vite25 (#126) * fix: remove trailing comma from tsconfig.json. see https://github.com/vitejs/vite/issues/4481 * fix: use import type to avoid error — committed to sveltejs/vite-plugin-svelte by dominikg 3 years ago
- fix: support dangling comma and circular dependency in tsconfig By implementing tsconfig resolve/parse/load logic in vite. Much of the code is from the `tsconfig` package and thanks to @dominikg Fix... — committed to sodatea/vite by sodatea 3 years ago
@dominikg tag you’re it
no, it’s a general issue with the 2.5.0 beta
now it fails
edited for clarity, it works in 2.4.4 and fails in 2.5.0-beta
However, dealing with the
typescriptpeer dependency* only for the trailing comma issue seems overkill to me. I don’t feel like putting effort into the extra complexity myself.Contributions are welcome, though.
*
typescriptmust be an optional peer dependency ofvite, so we have to check its existence during run time.