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

npm run build fails after project generation #1114

Closed
agdolla opened this issue Mar 29, 2024 · 3 comments · Fixed by #1117
Closed

npm run build fails after project generation #1114

agdolla opened this issue Mar 29, 2024 · 3 comments · Fixed by #1117
Assignees

Comments

@agdolla
Copy link

agdolla commented Mar 29, 2024

Hello!

After I created a new project and tried to build it, I get two errors:

npx create-electric-app@latest my-app --template react
npm run build

[email protected] build
tsc && vite build

src/generated/client/index.ts:3:38 - error TS6133: 'Relation' is declared but its value is never read.

3 import { type TableSchema, DbSchema, Relation, ElectricClient, type HKT } from 'electric-sql/client/model';
~~~~~~~~

src/generated/client/index.ts:298:11 - error TS2430: Interface 'ItemsGetPayload' incorrectly extends interface 'HKT'.
Types of property 'type' are incompatible.
Type 'ItemsGetPayload<this["_A"]>' is not assignable to type 'Record<string, any> | undefined'.
Type '"Please either choose select or include" | Items | { [x: string]: never; [x: number]: never; }' is not assignable to type 'Record<string, any> | undefined'.
Type 'string' is not assignable to type 'Record<string, any>'.

298 interface ItemsGetPayload extends HKT {
~~~~~~~~~~~~~~~

Found 2 errors in the same file, starting at: src/generated/client/index.ts:3

Copy link

linear bot commented Mar 29, 2024

@msfstef
Copy link
Contributor

msfstef commented Apr 1, 2024

Thank you for reporting the error!

The first error about Relation being declared but never read is going to be fixed by this PR #1117 hopefully part of the next release - in the meantime you can either remove it yourself or add a @ts-ignore annotation for it

The second error seems to occur with Typescript 5.4 - reverting to typescript version 5.3.3 will no longer result in this error. I will be looking into this, but fixing TS to 5.3.3 in the meantime should allow you to compile the client.

@agdolla
Copy link
Author

agdolla commented Apr 1, 2024

@msfstef ok thanks I try with TS 5.3.3

msfstef added a commit that referenced this issue Apr 3, 2024
…ests (#1117)

Relevant issues: #1001
#925
#1114

Only one thing is fixed in this PR, the `Relation` is no longer imported
if the data model has no relations in order to avoid `unused imports` TS
errors.

Main changes are moving all of the generator tests into their own test
directory rather than inside the source code, for consistency with the
TS client, ease of use, and improved reusability of test utilities.

I've also added a sort of integration test for the CLI generation step,
which is crucial to getting a working, compileable TS client as it
modifies some of the Prisma generated typings. This test generates the
client given a Prisma schema and performs all appropriate modifications
to it, and then attempts to compile it with TS and specified compiler
options.

Also found that with TS version >=5.4 we have [stricter conditional type
checking](https://devblogs.microsoft.com/typescript/announcing-typescript-5-4/#notable-behavioral-changes)
which breaks clients generated with Prisma versions earlier than 4.16.0
(see issue #1114),
however 4.16.0 introduces breaking changes with the "extensions"
feature, so I've added a hacky workaround for it:

https://github.com/electric-sql/electric/pull/1117/files#diff-fb0a50df4fc86f09b81a210162984d7822276fe19c8ae6496cf5ffe7d09f5adb

We can add more tests that would test various compiler options, making
it easier to avoid regressions when users report them with more
complicated schemas and TS compiler options.

Finally, I've added a Caution banner in our Usage section in the docs
about requiring TS `strict` mode, since Zod has that as a requirement as
well and its the reason why we see some inconsistencies in bug reports.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants