electric-sql / electric-sql/pglite

Expo API routes resolves `postgres.data` to the lambda API directory, despite using an absolute DB path

Open
#589 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
16k
Forks
442
Avg merge
20h 19m
Merged PRs (30d)
7

Description

I am trying to use PGLite with Drizzle via Expo's API routes.

Here is my Drizzle DB instance init:

![Image](https://github.com/user-attachments/assets/c533f1b7-021b-49d3-a25f-cd956aefee1a)

`process.cwd()` does resolve to the root project directory, which is supposed to contain my `.db` folder.
This is working when using a custom migration script that imports this `@/lib/db` file.

Unfortunately, when importing the same db instance (located at `@/lib/db`) from an API route, stored in `@/app/api/tests/db+api.ts`, PGLite tries to access the `postgres.data` file from that path, despite initializing the DB with the correct path (verified by `console.log`ging).

![Image](https://github.com/user-attachments/assets/9870b3cc-2f4e-434c-8fe8-0ac4b5549997)

This is probably a problem either with Expo's handling of API routes (at least in dev mode), Metro, or more likely a skill issue of mine.
Figured it might be useful to post this here anyway, since Drizzle support with Expo is explicitly stated in docs - albeit not specifically using API routes, which might apparently actually require a different setup.

I'm still trying to figure this out on my end and will report back here if I manage to fix anything. Hope filing this issue was the right thing to do as well - if not, I apologize!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.