prisma / nuxt-prisma

Prisma ORM integration for Nuxt
https://www.prisma.io/docs/orm/more/help-and-troubleshooting/help-articles/prisma-nuxt-module
57 stars 8 forks source link

Error: File URL host must be "localhost" or empty on linux, when opening Prisma Studio #26

Closed nicodel closed 2 weeks ago

nicodel commented 1 month ago

Hello,

I have been trying out nuxt-prisma to access sqlite3 databse from Nuxt application.

When I run yarn dev, setup seems fine and server starts fine, but when I go in the brower and I open the Prisma Studio I get the following error:

$ yarn dev
yarn run v1.22.22
$ nuxt dev
Nuxt 3.12.3 with Nitro 2.9.7                                                                                                    11:41:09
                                                                                                                                11:41:09
  ➜ Local:    http://localhost:3000/
  ➜ Network:  use --host to expose

✔ Prisma CLI is already installed.                                                                                             11:41:11
✔ Prisma schema file exists.                                                                                                   11:41:11
✔ Database migrations folder exists.                                                                                           11:41:11
                                                                                                                                11:41:11
Not migrating the database.
Generating Prisma client...                                                                                                     11:41:11

                                                                                                                                11:41:12
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (v5.17.0) to ./node_modules/@prisma/client in 46ms

✔ Do you want to view and edit your data by installing Prisma Studio in Nuxt DevTools? … yes
Starting Prisma Studio...                                                                                                       11:41:16

✔ Prisma Studio installed.                                                                                                     11:41:16
After clicking Get Started in Nuxt DevTools, click on the three dots (︙) in the lower left-hand side to reveal additional tabs.
Locate the Prisma logo to open Prisma Studio.

 WARN  Slow module @prisma/nuxt took 5275.93ms to setup.                                                                        11:41:16

  ➜ DevTools: press Shift + Alt + D in the browser (v1.3.9)                                                                     11:41:16

ℹ Vite client warmed up in 2396ms                                                                                              11:41:19
ℹ Vite server warmed up in 2662ms                                                                                              11:41:20
✔ Nuxt Nitro server built in 538 ms                                                                                      nitro 11:41:20
winstonLogger rebuild console
nuxt3-winston-log v0.5
ℹ Vuetify loeaded in Vue

 ERROR  File URL host must be "localhost" or empty on linux                                                                     11:41:24

  at getPathFromURLPosix (node:internal/url:1440:11)
  at fileURLToPath (node:internal/url:1464:63)
  at getPackageScopeConfig (node_modules/mlly/dist/index.mjs:663:32)
  at packageResolve (node_modules/mlly/dist/index.mjs:1814:25)
  at moduleResolve (node_modules/mlly/dist/index.mjs:1954:18)
  at _tryModuleResolve (node_modules/mlly/dist/index.mjs:2023:12)
  at _resolve (node_modules/mlly/dist/index.mjs:2078:16)
  at resolveSync (node_modules/mlly/dist/index.mjs:2111:10)
  at resolvePathSync (node_modules/mlly/dist/index.mjs:2121:24)
  at _resolve (node_modules/local-pkg/dist/index.mjs:288:22)

The install on nuxt-install is clean, with the default Models in prisma.schema and a sqlite database with below URL:

DATABASE_URL="file:./dev.db"
ankur-arch commented 1 month ago

Hey there @nicodel 👋 , thanks for creating the issue. Could you share the generated prisma schema?

nicodel commented 1 month ago

Sure. Here it is:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = env("DATABASE_URL")
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  author    User    @relation(fields: [authorId], references: [id])
  authorId  Int
}
ankur-arch commented 1 month ago

Thanks, @nicodel,

As the setup and migration worked fine, it seems Prisma Studio is failing to read the database URL from the nuxt devtools. Could you try using the absolute URL of the SQLite db file and see if that helps:

datasource db {
  provider = "sqlite"
  url      =  "file:/Users/janedoe/dev.db" // absolute path to URL
}

Also, can you check whether Prisma Studio works for you manually by running:

npx prisma studio

What OS and version are you using? I'm wondering if this issue might be related.

nicodel commented 1 month ago

Hello @ankur-arch ,

I tried to use the absolute path, but got the same error message.

datasource db {
  provider = "sqlite"
  url      = "file:/home/nicodel/dev/countdowns/prisma/dev.db"
}

But the Prisma Studio alone do not fire errors:

$ npx prisma studio
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Prisma Studio is up on http://localhost:5555

I am running under Debian 12 (bookworm).

If I understood the issue you mentioned, nitropack needs to be >0.5.0, I got 2.9.7:

$ yarn list --pattern nitropack
yarn list v1.22.22
└─ nitropack@2.9.7
ankur-arch commented 1 month ago

Thanks for all the details @nicodel. I can't seem to reproduce this 😞 , would you have a reproduction of this I can use?

nicodel commented 1 month ago

Hello @ankur-arch ,

My project is stored in a GitLab repository. Please navigate to the nuxt-prisma branch to get the code concerned by this issue.

Countdowns [nuxt-prisma]

ankur-arch commented 1 month ago

Update on this, the app is working smoothly in my macos. I'll try reproducing this in linux and see if it's an OS specific issue.

image
nicodel commented 1 month ago

Thanks for working on this

ankur-arch commented 2 weeks ago

Hey @nicodel 👋 , we couldn't reproduce this issue 😞 .

I'm closing this and will add an additional param to pass the url of prisma studio ( that will possibly be fix the issue you're facing ).