0

I am trying to build my sveltekit app and then ship the build onto a vm.

As can be seen from the release script, I am having to copy the prisma.schema file manually and run 'npx prisma generate' on the vm.

host="XXX"
app_name="dashboard"

# NAVIGATE TO THE PROJECT ROOT
cd ../../

# # BUILD THE PACKAGE
npm run build --MODE=production

# # DELETE THE CONTENT OF THE REMOTE FOLDER
ssh root@$host 'rm -rf /home/dashboard/*'

# # COPY THE PACKAGE TO THE REMOTE MACHINE
scp -r package.json  package-lock.json prisma/schema.prisma root@$host:/home/dashboard/

ssh root@$host bash -s  << HERE
    cd /home/dashboard/
    # npm ci --omit dev
    npm i  
    npx prisma generate
    pm2 stop /home/dashboard/build/index.js --name $app_name 2>/dev/null
    pm2 delete /home/dashboard/build/index.js --name $app_name
    HOST=127.0.0.1 PORT=3000 pm2 start /home/dashboard/build/index.js --name $app_name --log-date-format 'MMM DD HH:mm:ss'
    
HERE

It generates a prisma client however I get the following error `

26|dashboard  | May 19 15:18:06: error: Environment variable not found: DATABASE_URL.
26|dashboard  | May 19 15:18:06:   -->  schema.prisma:9
26|dashboard  | May 19 15:18:06:    | 
26|dashboard  | May 19 15:18:06:  8 |   provider = "mysql"
26|dashboard  | May 19 15:18:06:  9 |   url      = env("DATABASE_URL")
26|dashboard  | May 19 15:18:06:    | 

The questions I have:

  1. Why is Vite not able to ship prisma client with the build
  2. In SvelteKit, to get an env variable, i use
import { DATABASE_URL } from '$env/static/private'; 

How can i use that syntax to provide the environment variable to the schema.prisma file

  1. This feels long winded, is there a better approach?

Thanks

I tried the above. Not sure what to do next.

Duncan
  • 45
  • 1
  • 4

1 Answers1

0

The DATABASE_URL is loaded from your .env file or the system environment variable. If you use .env for DATABASE_URL, check your local development machine, you will find the .env file under your project root. The solution is to create a .env file in your server and put whatever DATABASE_URL in it. Also, run npx prisma generate according to this answer: prisma - getting environment variable not found error message when running graphql query

Lin
  • 1
  • 1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/34674630) – Jan Jul 14 '23 at 09:21