NodeJS Supabase连接返回未定义

fjaof16o  于 2023-05-06  发布在  Node.js
关注(0)|答案(1)|浏览(126)

bounty还有5天到期。回答此问题可获得+50声望奖励。pech0rin希望引起更多关注这个问题。

我有一个Vercel部署的Remix项目,在后端使用Supabase,Postgresql并使用Prisma作为ORM。我已经设置了连接池以及到Supabase的直接连接,但每当我尝试在本地连接时,我都会得到这个错误:

🔌 setting up prisma client to undefined.db.ubixifkwxkflnueueaku.supabase.co:6543
✅ app ready: http://localhost:3000
✅ metrics ready: http://localhost:3001/metrics

C:\Users\TylerD\Desktop\dev\TheCityGomorrah\node_modules\@prisma\client\runtime\library.js:101
You may have to run ${Gt.default.greenBright("prisma generate")} for your changes to take effect.`,this.config.clientVersion);return r}parseEngineResponse(r){if(!r)throw new W("Response from the Engine was empty",{clientVersion:this.config.clientVersion});try{return JSON.parse(r)}catch{throw new W("Unable to JSON.parse response from engine",{clientVersion:this.config.clientVersion})}}convertDatasources(r){let n=Object.create(null);for(let{name:i,url:o}of r)n[i]=o;return n}async loadEngine(){if(!this.engine){this.QueryEngineConstructor||(this.library=await this.libraryLoader.loadLibrary(),this.QueryEngineConstructor=this.library.QueryEngine);try{let r=new WeakRef(this);this.engine=new this.QueryEngineConstructor({datamodel:this.datamodel,env:process.env,logQueries:this.config.logQueries??!1,ignoreEnvVarErrors:!0,datasourceOverrides:this.datasourceOverrides,logLevel:this.logLevel,configDir:this.config.cwd,engineProtocol:this.engineProtocol},n=>{r.deref()?.logger(n)}),Nl++}catch(r){let n=r,i=this.parseInitError(n.message);throw typeof i=="string"?n:new G(i.message,this.config.clientVersion,i.error_code)}}}logger(r){let n=this.parseEngineResponse(r);if(!!n){if("span"in n){this.config.tracingConfig.enabled===!0&&co(n);return}n.level=n?.level.toLowerCase()??"unknown",Vd(n)?this.logEmitter.emit("query",{timestamp:new Date,query:n.query,params:n.params,duration:Number(n.duration_ms),target:n.module_path}):Qd(n)?this.loggerRustPanic=new ce(this.getErrorMessageWithLink(`${n.message}: ${n.reason} in ${n.file}:${n.line}:${n.column}`),this.config.clientVersion):this.logEmitter.emit(n.level,{timestamp:new Date,message:n.message,target:n.module_path})}}getErrorMessageWithLink(r){return Ya({platform:this.platform,title:r,version:this.config.clientVersion,engineVersion:this.versionInfo?.commit,database:this.config.activeProvider,query:this.lastQuery})}parseInitError(r){try{return JSON.parse(r)}catch{}return r}parseRequestError(r){try{return JSON.parse(r)}catch{}return r}on(r,n){r==="beforeExit"?this.beforeExitListener=n:this.logEmitter.on(r,n)}async start(){if(await this.libraryInstantiationPromise,await this.libraryStoppingPromise,this.libraryStartingPromise)return je(`library already starting, this.libraryStarted: ${this.libraryStarted}`),this.libraryStartingPromise;if(this.libraryStarted)return;let r=l(async()=>{je("library starting");try{let i={traceparent:Ne({tracingConfig:this.config.tracingConfig})};await this.engine?.connect(JSON.stringify(i)),this.libraryStarted=!0,je("library started")}catch(i){let o=this.parseInitError(i.message);throw typeof o=="string"?i:new G(o.message,this.config.clientVersion,o.error_code)}finally{this.libraryStartingPromise=void 0}},"startFn"),n={name:"connect",enabled:this.config.tracingConfig.enabled};return this.libraryStartingPromise=fe(n,r),this.libraryStartingPromise}async stop(){if(await this.libraryStartingPromise,await this.executingQueryPromise,this.libraryStoppingPromise)return je("library is already stopping"),this.libraryStoppingPromise;if(!this.libraryStarted)return;let r=l(async()=>{await new Promise(o=>setTimeout(o,5)),je("library stopping");let i={traceparent:Ne({tracingConfig:this.config.tracingConfig})};await this.engine?.disconnect(JSON.stringify(i)),this.libraryStarted=!1,this.libraryStoppingPromise=void 0,je("library stopped")},"stopFn"),n={name:"disconnect",enabled:this.config.tracingConfig.enabled};return this.libraryStoppingPromise=fe(n,r),this.libraryStoppingPromise}async getDmmf(){await this.start();let r=Ne({tracingConfig:this.config.tracingConfig}),n=await this.engine.dmmf(JSON.stringify({traceparent:r}));return fe({name:"parseDmmf",enabled:this.config.tracingConfig.enabled,internal:!0},()=>JSON.parse(n))}version(){return this.versionInfo=this.library?.version(),this.versionInfo?.version??"unknown"}debugPanic(r){return this.library?.debugPanic(r)}async request(r,{traceparent:n,interactiveTransaction:i}){je(`sending request, this.libraryStarted: ${this.libraryStarted}`);let o=JSON.stringify({traceparent:n}),s=JSON.stringify(r);try{await this.start(),this.executingQueryPromise=this.engine?.query(s,o,i?.id),this.lastQuery=s;let a=this.parseEngineResponse(await this.executingQueryPromise);if(a.errors)throw a.errors.length===1?this.buildQueryError(a.errors[0]):new W(JSON.stringify(a.errors),{clientVersion:this.config.clientVersion});if(this.loggerRustPanic)throw this.loggerRustPanic;return{data:a,elapsed:0}}catch(a){if(a instanceof G)throw a;if(a.code==="GenericFailure"&&a.message?.startsWith("PANIC:"))throw new ce(this.getErrorMessageWithLink(a.message),this.config.clientVersion);let u=this.parseRequestError(a.message);throw typeof u=="string"?a:new W(`${u.message}
                                                                                                                                          
     ^
Error: Can't reach database server at `undefined.db.ubixifkwxkflnueueaku.supabase.co`:`6543`

Please make sure your database server is running at `undefined.db.ubixifkwxkflnueueaku.supabase.co`:`6543`.
    at startFn (C:\Users\TylerD\Desktop\dev\TheCityGomorrah\node_modules\@prisma\client\runtime\library.js:101:2598)

同样,如果我尝试在Vercel部署中注册用户,它可以工作,但不会在数据库中存储任何内容。但是在尝试登录时,它在Vercel日志中给了我一个类似的错误:

Unhandled Promise Rejection     {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"Error: Can't reach database server at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`\n\nPlease make sure your database server is running at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`.","reason":{"errorType":"Error","errorMessage":"Can't reach database server at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`\n\nPlease make sure your database server is running at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`.","clientVersion":"4.11.0","errorCode":"P1001","stack":["Error: Can't reach database server at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`","","Please make sure your database server is running at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`.","    at startFn (/var/task/node_modules/@prisma/client/runtime/library.js:101:2598)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: Error: Can't reach database server at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`","","Please make sure your database server is running at `undefined.db.ijpeuroobfrvafcvrtfa.supabase.co`:`5432`.","    at process.<anonymous> (file:///var/runtime/index.mjs:1188:17)","    at process.emit (node:events:525:35)","    at process.emit (/var/task/node_modules/source-map-support/source-map-support.js:516:21)","    at emit (node:internal/process/promises:149:20)","    at processPromiseRejections (node:internal/process/promises:283:27)","    at processTicksAndRejections (node:internal/process/task_queues:96:32)"]}
Unknown application error occurred
Runtime.Unknown

现在显然没有任何存储在数据库中,我也无法检索它。但为了清楚起见,这些是日志。
我的.env有DATABASE_URL用于连接池,DIRECT_URL用于迁移更新等-我已经仔细检查了凭据,并搜索了Prisma和Supabase的文档,我已经查看了GH问题页面,找不到任何关于这一点的信息。
Supabase日志返回以下内容:

Log ID
bba2af3c-2839-40ca-be4a-44a7c54dcb2c

Log Timestamp (UTC)
2023-04-02T21:44:16.257Z

Log Event Message
C-0xaaaadd3c6810: pgbouncer/pgbouncer@127.0.0.1:56654 closing because: SASL authentication failed (age=0s)

Log Metadata
[
  {
    "PRIORITY": null,
    "SYSLOG_FACILITY": null,
    "SYSLOG_IDENTIFIER": null,
    "_BOOT_ID": null,
    "_CAP_EFFECTIVE": null,
    "_CMDLINE": null,
    "_COMM": null,
    "_EXE": null,
    "_GID": null,
    "_MACHINE_ID": null,
    "_PID": null,
    "_SELINUX_CONTEXT": null,
    "_SOURCE_REALTIME_TIMESTAMP": null,
    "_STREAM_ID": null,
    "_SYSTEMD_CGROUP": null,
    "_SYSTEMD_INVOCATION_ID": null,
    "_SYSTEMD_SLICE": null,
    "_SYSTEMD_UNIT": null,
    "_TRANSPORT": null,
    "_UID": null,
    "__MONOTONIC_TIMESTAMP": null,
    "__REALTIME_TIMESTAMP": null,
    "file": null,
    "host": "db-ubixifkwxkflnueueaku",
    "metadata": [],
    "project": null,
    "source_type": null
  }
]
yhived7q

yhived7q1#

今天我也遇到了同样的事情。问题是,当您将其设置为动态部署时。它会自动在app/db.server.ts文件中添加一堆额外的配置。具体来说,就是在getClient()函数中操作prisma客户端。
我的建议(快速启动和运行是用这个替换):

function getClient() {
  const { DATABASE_URL } = process.env;
  invariant(typeof DATABASE_URL === "string", "DATABASE_URL env var not set");
  console.log(`🔌 setting up prisma client to DATABASE_URL`);

  const client = new PrismaClient()

  // connect eagerly
  client.$connect();

  return client;
}

相关问题