[GH-ISSUE #601] CLI fails to generate migrations if tsconfig contains trailing comma #16967

Closed
opened 2026-04-15 14:54:44 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @jakst on GitHub (Nov 20, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/601

Describe the bug
When the tsconfig.json file in the project contains a trailing comma (which is valid JSONC), the CLI fails to run some commands.

> pnpx @better-auth/cli generate

SyntaxError: Expected double-quoted property name in JSON at position 624 (line 25 column 3)
    at JSON.parse (<anonymous>)
    at ie (node_modules/.pnpm/@better-auth+cli@0.8.8_@babel+core@7.26.0_kysely@0.27.4/node_modules/@better-auth/cli/dist/index.mjs:9:1169)
    at q (node_modules/.pnpm/@better-auth+cli@0.8.8_@babel+core@7.26.0_kysely@0.27.4/node_modules/@better-auth/cli/dist/index.mjs:9:1497)
    at P (node_modules/.pnpm/@better-auth+cli@0.8.8_@babel+core@7.26.0_kysely@0.27.4/node_modules/@better-auth/cli/dist/index.mjs:9:2109)
    at Command.Ae (node_modules/.pnpm/@better-auth+cli@0.8.8_@babel+core@7.26.0_kysely@0.27.4/node_modules/@better-auth/cli/dist/index.mjs:27:632)
    at Command.listener [as _actionHandler] (node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:542:17)
    at node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1502:14
    at Command._chainOrCall (node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1386:12)
    at Command._parseCommand (node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1501:27)
    at node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1265:27

 ERROR   [#better-auth]: Couldn't read your auth config. Error parsing tsconfig.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new better-auth project
  2. Use a very simple tsconfig with a trailing comma, like this one
{
  "compilerOptions": {},
}
  1. Run pnpx @better-auth/cli generate
Originally created by @jakst on GitHub (Nov 20, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/601 **Describe the bug** When the `tsconfig.json` file in the project contains a trailing comma (which is valid JSONC), the CLI fails to run some commands. ``` > pnpx @better-auth/cli generate SyntaxError: Expected double-quoted property name in JSON at position 624 (line 25 column 3) at JSON.parse (<anonymous>) at ie (node_modules/.pnpm/@better-auth+cli@0.8.8_@babel+core@7.26.0_kysely@0.27.4/node_modules/@better-auth/cli/dist/index.mjs:9:1169) at q (node_modules/.pnpm/@better-auth+cli@0.8.8_@babel+core@7.26.0_kysely@0.27.4/node_modules/@better-auth/cli/dist/index.mjs:9:1497) at P (node_modules/.pnpm/@better-auth+cli@0.8.8_@babel+core@7.26.0_kysely@0.27.4/node_modules/@better-auth/cli/dist/index.mjs:9:2109) at Command.Ae (node_modules/.pnpm/@better-auth+cli@0.8.8_@babel+core@7.26.0_kysely@0.27.4/node_modules/@better-auth/cli/dist/index.mjs:27:632) at Command.listener [as _actionHandler] (node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:542:17) at node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1502:14 at Command._chainOrCall (node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1386:12) at Command._parseCommand (node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1501:27) at node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1265:27 ERROR [#better-auth]: Couldn't read your auth config. Error parsing tsconfig. ``` **To Reproduce** Steps to reproduce the behavior: 1. Create a new better-auth project 2. Use a very simple tsconfig with a trailing comma, like this one ``` { "compilerOptions": {}, } ``` 3. Run `pnpx @better-auth/cli generate`
GiteaMirror added the locked label 2026-04-15 14:54:44 -05:00
Author
Owner

@zAlweNy26 commented on GitHub (Nov 20, 2024):

@jakst that's normal behavior, trailing comma is not allowed in JSON if it's the last item of an object.
As you can see:
image

<!-- gh-comment-id:2488686536 --> @zAlweNy26 commented on GitHub (Nov 20, 2024): @jakst that's normal behavior, trailing comma is not allowed in JSON if it's the last item of an object. As you can see: ![image](https://github.com/user-attachments/assets/eeca4f54-0c2c-4d67-a092-a5322e293a8a)
Author
Owner

@jakst commented on GitHub (Nov 20, 2024):

@jakst that's normal behavior, trailing comma is not allowed in JSON if it's the last item of an object. As you can see:

tsconfig.json is not pure json. It's JSONC, which supports comments and trailing commas.

The problem in our code base is that prettier is set up with trailing commas, and since it knows tsconfig is jsonc it will add a trailing comma on every save.

It's possible to work around of course, but lot's of code bases will have trailing commas in their tsconfig, which means they'll get that confusing error message when trying to run the CLI.

<!-- gh-comment-id:2488780496 --> @jakst commented on GitHub (Nov 20, 2024): > @jakst that's normal behavior, trailing comma is not allowed in JSON if it's the last item of an object. As you can see: tsconfig.json is not pure json. It's JSONC, which supports comments and trailing commas. The problem in our code base is that prettier is set up with trailing commas, and since it knows tsconfig is jsonc it will add a trailing comma on every save. It's possible to work around of course, but lot's of code bases will have trailing commas in their tsconfig, which means they'll get that confusing error message when trying to run the CLI.
Author
Owner

@Bekacru commented on GitHub (Nov 20, 2024):

fixed on v1.0.0-canary.8. feel free to re-open if not.

<!-- gh-comment-id:2489475841 --> @Bekacru commented on GitHub (Nov 20, 2024): fixed on `v1.0.0-canary.8`. feel free to re-open if not.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#16967