Closed Fr3akyMurk closed 4 months ago
@iamtouha I forgot to add some details. For local development i use a locally hosted mysql server, so basically the project is currently completely cut off from the web. apparently this bug is already known within drizzle and has a workaround for, however this did not help me as it changed from ssl error to a port 443 error.
⨯ TypeError: fetch failed
at async login (./src/lib/auth/actions.ts:64:26)
Cause: Error: connect ECONNREFUSED 127.0.0.1:443
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 443
}
Refer to this Issue for further details.
Hi @Fr3akyMurk , have you tried removing ?ssl={"rejectUnauthorized":true}
part from DATABASE_URL for local development?
Hello, @iamtouha
Yeah i have removed it and tried many different ways to connect to the db but it always results in an error.
I've tried ?allowPublicKeyRetrieval=true
and &useSSL=false
Although i am unsure if &useSSL=false
does any change, it certainly doesn't when used in practice.
For some reason mysql databases ?allowPublicKeyRetrieval
is required, this is probably connected to SSL stuff.
(unreliable, sometimes it wants this sometimes it does not)
My connection string looks like this, it's quite similar to planetscales url.
mysql://<user>:<password>@localhost:3306/luciatest?allowPublicKeyRetrieval=true&useSSL=false
Okay so, i did some digging. I played around and changed a few things.
More prominently, i checked the migration code and applied it to the index file.
This seems to resolve the connection issues but then the code starts to complain about an await statement in a top level module.
import mysql from "mysql2/promise";
//import { drizzle } from "drizzle-orm/planetscale-serverless";
import { drizzle } from "drizzle-orm/mysql2";
//import { Connection } from "@planetscale/database";
import { env } from "@/env";
import * as schema from "./schema";
//export const connection = new Connection({ url: env.DATABASE_URL });
//export const db = drizzle(connection, { schema });
const connection = await mysql.createConnection(env.DATABASE_URL);
export const db = drizzle(connection, { schema, mode: "default" })
Figured this information would be better off to be sent to you considering you made majority of the code.
Unhandled Runtime Error
Error: await is only valid in async functions and the top level bodies of modules
Call Stack
(action-browser)/./src/server/db/index.ts
/home/mark/nextjs-typescript-starter/next-lucia-auth/.next/server/app/(auth)/login/page.js (904:1)
mysql.createConnection
is not an async function. please remove the await
before the function call and see if the error persists.
That is true, mysql.createConnection
is not a async function, i thought i removed that to try, regardless it errors eitherway.
Although this time it errors because client.query
is not a valid function.
Unhandled Runtime Error
Error: client.query is not a function
Call Stack
query
node_modules/.pnpm/drizzle-orm@0.28.6_@planetscale+database@1.11.0_mysql2@3.6.5/node_modules/drizzle-orm/mysql2/index.mjs (52:36)
execute
node_modules/.pnpm/drizzle-orm@0.28.6_@planetscale+database@1.11.0_mysql2@3.6.5/node_modules/drizzle-orm/view-23898f21.mjs (1382:30)
execute
node_modules/.pnpm/drizzle-orm@0.28.6_@planetscale+database@1.11.0_mysql2@3.6.5/node_modules/drizzle-orm/alias-cf8e03cd.mjs (363:20)
process.processTicksAndRejections
node:internal/process/task_queues (95:5)
node_modules/.pnpm/drizzle-orm@0.28.6_@planetscale+database@1.11.0_mysql2@3.6.5/node_modules/drizzle-orm/mysql2/index.mjs (52:36) @ query
⨯ Internal error: TypeError: client.query is not a function
at MySql2PreparedQuery.execute (./node_modules/.pnpm/drizzle-orm@0.28.6_@planetscale+database@1.11.0_mysql2@3.6.5/node_modules/drizzle-orm/mysql2/index.mjs:61:37)
at QueryPromise.execute (./node_modules/.pnpm/drizzle-orm@0.28.6_@planetscale+database@1.11.0_mysql2@3.6.5/node_modules/drizzle-orm/view-23898f21.mjs:1475:31)
at QueryPromise.then (./node_modules/.pnpm/drizzle-orm@0.28.6_@planetscale+database@1.11.0_mysql2@3.6.5/node_modules/drizzle-orm/alias-cf8e03cd.mjs:504:21)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
db.query() is not callable at least according to vscode. the drizzle connection is now also complaining now that the await is removed.
Argument of type 'Promise<Connection>' is not assignable to parameter of type 'MySql2Client | Connection | Pool'.ts(2345)
index.ts(13, 27): Did you forget to use 'await'?
const connection: Promise<mysql.Connection>
dang! use await before mysql.createConnection
.
which node version are you using? also, what is set on your compilerOptions.taget
value in tsconfig file?
Alright, i have reverted to the code that was posted.
I use node 20.9.0, i am aware that newer versions are available but right now i doubt it's relevant.
I think you meant compilerOptions.target
, to answer, it's currently set at "es2022".
I also thought a bit about it, but it could be that the connection still fails but we don't know that because the code running fails before the connection even happens, i will have to check mysql logs if i want to know if the app even connects.
~~Are you ok with trying postgresql? (not to switch the project to it, just to see if it works better) I will see if it's just mysql that is being wonky. I'll keep you updated.~~
I will try with different mysql servers. however in the meantime, while making this project did you at any point have ssl checks?
@Fr3akyMurk No. drizzle connects smoothly with planetscale using DB_URL
Well yeah, and so does it with any local databases, however this time it just has issues. To be fair i have never used mysql with connectionsteings in projects before so i don't really know what the issue may be.
I do not understand anything with this. It is not a problem on my system only as i have tried this on my main computer, my laptop and a vm. The error persists either way.
There is little to no documentation on this error and how to fix it. Using Planetscales link to connect does not work because i get the same SSL issue (different issue but still SSL related)
How do you develop the project? Locally or somehow in the cloud? I am unaware of any way to develop directly in the cloud.
@iamtouha I got a workaround, although it is most likely not ideal for use with this project. Primarily because it has a lot of changes.
My current drizzle index code looks like this:
/*
import { drizzle } from "drizzle-orm/planetscale-serverless";
import { Connection } from "@planetscale/database";
import { env } from "@/env";
import * as schema from "./schema";
export const connection = new Connection({ url: env.DATABASE_URL });
export const db = drizzle(connection, { schema });
*/
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import { env } from "@/env";
import * as schema from "./schema";
async function connect() {
const connection = await mysql.createConnection({
host: "127.0.0.1",
user: "MariaInterface",
password: "MARIADB",
port: 3306,
database: "lucia",
});
const db = drizzle(connection, {schema, mode: "planetscale"})
return db
}
export const udb = connect();
This solves the conncetionissues, however i don't know if this would work to connect to planetscale but i can take a look into it. (SSL errors, cannot check myself)
However, now i have to go through all the code that imports db and await it. But it does solve my issue(s)
Do note that this should not be used, at least not here considering i don't know if this is compatible with planetscale or other devices, all i know is that this works for me. + i made plenty more changes in:
Could you please spare some time to create a PR with the changes you made? I will add these changes to a new branch so that someone facing the same problem will benefit.
Alright, i will look into it.
I will not add my changes, those changes are not reasonable. However Kinfish (the other contributor) found a much better solution, he uses pg drivers instead of mysql promise based drivers, i will look into that and if it works i will open a pr with that solution for you to view.
My edits are too dramatic for something so simple.
Greetings, I have an issue on my local build for development where i cannot get the application to properly connect to the DB because of a SSL issue.
I keep getting this issue at:
Problem is, this is a completely fresh clone from github, the .env is the only edited part. How can i solve this error?