Giter Site home page Giter Site logo

Comments (18)

barbalex avatar barbalex commented on June 7, 2024

I don't know if the two things are related but I tried the same process after updating:

  • electric-sql from 0.7.1 to 0.8.1
  • @electric-sql/prisma-generator from 1.1.0 to 1.1.1

Then:

  1. npm run backend:down
  2. npm run backend:start
  3. db:migrate
  4. client:generate

generating now fails with:

alex@pop-os:~/ps$ npm run client:generate

> [email protected] client:generate
> npm run electric:check && npx electric-sql generate --service http://localhost:5133 --proxy postgresql://prisma:proxy_password@localhost:65432/electric


> [email protected] electric:check
> node ./check-electric-is-running.js

DATABASE_URL: postgresql://postgres:proxy_password@localhost:65432/ps
Generating Electric client...
Successfully generated Electric client at: ./src/generated/client
Building migrations...
generate command failed: TypeError: Cannot read properties of undefined (reading 'sqliteType')

from electric.

kevin-dp avatar kevin-dp commented on June 7, 2024

I don't know if the two things are related but I tried the same process after updating:

* electric-sql from 0.7.1 to 0.8.1

* @electric-sql/prisma-generator from 1.1.0 to 1.1.1

Then:

1. `npm run backend:down`

2. `npm run backend:start`

3. `db:migrate`

4. `client:generate`

generating now fails with:

alex@pop-os:~/ps$ npm run client:generate

> [email protected] client:generate
> npm run electric:check && npx electric-sql generate --service http://localhost:5133 --proxy postgresql://prisma:proxy_password@localhost:65432/electric


> [email protected] electric:check
> node ./check-electric-is-running.js

DATABASE_URL: postgresql://postgres:proxy_password@localhost:65432/ps
Generating Electric client...
Successfully generated Electric client at: ./src/generated/client
Building migrations...
generate command failed: TypeError: Cannot read properties of undefined (reading 'sqliteType')

Hi @barbalex, i created a fresh project using npx create-electric-app@latest and double checked to have the same versions of electric-sql and the generator that you are using. Everything works fine on my end. Could you share your Postgres schema such that i can try to reproduce the error?

from electric.

barbalex avatar barbalex commented on June 7, 2024

@kevin-dp
Here is the schema: https://github.com/barbalex/ps/tree/main/db/migrations

By the way: I did not run a new npx create-electric-app@latest, just updated.

from electric.

barbalex avatar barbalex commented on June 7, 2024

As this blocks me from developing the app, I am trying to isolate the error.

My app builds 40 tables.

I have reduced the number of tables to find tables whose client generation causes this error.

So far I have found one: https://github.com/barbalex/ps/blob/main/db/migrations/02-accounts.sql#L5

When I only build 01 and 02, this table's owner_user_id field causes the error. Renaming it to user_id solves it.

As there are other tables causing errors I will keep searching.

from electric.

barbalex avatar barbalex commented on June 7, 2024

Another failing table is: https://github.com/barbalex/ps/blob/main/db/migrations/39-fields.sql

There were two offending fields:

  • type text DEFAULT NULL REFERENCES field_types(field_type) ON DELETE CASCADE ON UPDATE CASCADE: had to rename to field_type to make it work
  • widget text DEFAULT NULL REFERENCES widget_types(widget_type) ON DELETE CASCADE ON UPDATE CASCADE: had to rename to widget_type to get it work.

So it seems there is a requirement that all referencing fields need to be named exactly the same as the referenced field.

That would make building self-referencing tables impossible (parent-child relationships).

from electric.

barbalex avatar barbalex commented on June 7, 2024

Now that generating the client works again, I am back to the original error:

common.js:1 Uncaught (in promise) TypeError: globalThis.uuid is not a function
    at S2 (common.js:1:1069)
    at he2._getClientId (process.js:62:2512)
    at async he2.start (process.js:1:2461)
    at async b10.startProcess (registry.js:1:1763)

...which unfortunately also blocks development of the app.

from electric.

barbalex avatar barbalex commented on June 7, 2024

So it seems there is a requirement that all referencing fields need to be named exactly the same as the referenced field. That would make building self-referencing tables impossible (parent-child relationships).

Actually I have exactly that in my models: https://github.com/barbalex/ps/blob/main/db/migrations/14-places.sql#L5

And that works?

from electric.

barbalex avatar barbalex commented on June 7, 2024

concerning globalThis.uuid is not a function

I tried:

  • changing globalThis in common.js to self/this/global. Nope.
    The problem is not globalThis but the missing of the uuid function
  • npm i --save uuid. Nope
  • npm i -g uuid. Nope

To be honest I have no idea where common.js is running and thus how to add the uuid function to that environment.

uuid is correctly installed by electric itself:

alex@pop-os:~/ps$ npm why uuid
[email protected]
node_modules/uuid
  uuid@"^9.0.0" from [email protected]
  node_modules/electric-sql
    electric-sql@"0.8.2" from the root project

This error occurs on my pop os pc and my MacOS notebook.

from electric.

kevin-dp avatar kevin-dp commented on June 7, 2024

As this blocks me from developing the app, I am trying to isolate the error.

My app builds 40 tables.

I have reduced the number of tables to find tables whose client generation causes this error.

So far I have found one: https://github.com/barbalex/ps/blob/main/db/migrations/02-accounts.sql#L5

When I only build 01 and 02, this table's owner_user_id field causes the error. Renaming it to user_id solves it.

As there are other tables causing errors I will keep searching.

I tried reproducing your error but didn't manage yet. On a fresh Electric app, i created your users and accounts tables (just the tables without the indexes) and electrified them. Then i generated the client without problems. I'm using [email protected] and @electric-sql/[email protected].

I also copied all your migrations, applied them all on a fresh electric app, and the client builds without any issues.

from electric.

barbalex avatar barbalex commented on June 7, 2024

O.k., so I rebuilt my project from a fresh electric app too, and it now works.

Sorry for bugging you and thanks for your help!

from electric.

barbalex avatar barbalex commented on June 7, 2024

So after having lunch I returned to my pc and the issue is back 😢
It happens in chrome and firefox.

from electric.

kevin-dp avatar kevin-dp commented on June 7, 2024

So after having lunch I returned to my pc and the issue is back 😢 It happens in chrome and firefox.

Just to double check that we are talking about the same.
The issue that is back is the uuid function not being found, right?
I believe @samwillis has a fix for this. I'll ask him to give you an update about the status of that fix.

What about this other issue:

generate command failed: TypeError: Cannot read properties of undefined (reading 'sqliteType')

Does it still happen on your original migrations? I could not reproduce that using the 40 migrations you shared.

from electric.

barbalex avatar barbalex commented on June 7, 2024

The issue that is back is the uuid function not being found, right?

Correct. Sorry for mixing up stuff.

Does it still happen on your original migrations?

I renamed the fields to make them work. Would you like me to test with the original names?

from electric.

kevin-dp avatar kevin-dp commented on June 7, 2024

The issue that is back is the uuid function not being found, right?

Correct. Sorry for mixing up stuff.

Does it still happen on your original migrations?

I renamed the fields to make them work. Would you like me to test with the original names?

Yes if you could test with the original names. The 40 migrations in the repo you shared, are that the original names or the renamed ones? Because those worked for me.

from electric.

barbalex avatar barbalex commented on June 7, 2024

So I did this:

  • using the up-to-date version of my app
  • reverted three fields in the migrations:
    • accounts.user_id > accounts.owning_user_id
    • fields.field_type > fields.type
    • fields.widget_type > fields.widget
  • tested: yes fails with generate command failed: TypeError: Cannot read properties of undefined (reading 'sqliteType')
  • created a new branch from it for you to test with: https://github.com/barbalex/ps/tree/type_error_generating_client

from electric.

kevin-dp avatar kevin-dp commented on June 7, 2024

Regarding uuid, @samwillis fixed his issue here 6bbe71a
Perhaps this solves it for you?

from electric.

barbalex avatar barbalex commented on June 7, 2024

How can I test it? (the code needs to be compiled, I couldn't just copy it over)

from electric.

barbalex avatar barbalex commented on June 7, 2024

O.k., so I converted it from typescript to js and replaced the typescript common.js files code in my node_modules folder.

And it works!

Thanks you guys so much!

from electric.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.