W
Wasp4w ago
Gwaggli

wasp build start

Feels really stupid to ask this but i can't manage to get wasp build startrunning. I always get the message, that the DATABASE_URL is not defined (from the prisma file). But i run DATABASE_URL=<url> wasp build and even if i run DATABASE_URL=<url> wasp build start afterwards i get the exact same error. What am I missing?
10 Replies
kapa.ai
kapa.ai4w ago
Hi @Gwaggli. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- You're not alone—this is a common point of confusion with Wasp and Prisma. Here’s what’s happening and how to resolve it: Why the error occurs When you run wasp build, Prisma tries to read the DATABASE_URL environment variable to generate the client. If it’s not set, you’ll see an error like:
error: Environment variable not found: DATABASE_URL
error: Environment variable not found: DATABASE_URL
Even if you set DATABASE_URL inline for the build, it won’t persist for the next command (wasp start). Each command runs in its own shell, so the environment variable isn’t carried over unless you set it in a way that both commands can access it. This is a known issue and has been discussed in several places. The error is confusing but does not always prevent the build from succeeding, though it can block you if the variable is truly missing at runtime or during migrations. The root cause is that Prisma expects DATABASE_URL to be available whenever it runs, including during build steps, and Wasp does not always provide it explicitly in every context. This is especially visible during wasp build and wasp start if the environment variable is not set properly or not found in the expected place (Github Issue #1282, Github Issue #1321). How to fix it Recommended approach:
Create a .env.server file in the root of your Wasp project and add your DATABASE_URL there. For example:
.env.server
DATABASE_URL=postgresql://user:password@host:port/dbname
.env.server
DATABASE_URL=postgresql://user:password@host:port/dbname
Wasp will automatically load this file for both build and start commands, ensuring Prisma always has access to the variable (Wasp Docs: Defining Env Vars in Development). Alternative (not recommended for regular use):
You can set the environment variable inline for each command, but you must do it for both wasp build and wasp start:
DATABASE_URL=<url> wasp build
DATABASE_URL=<url> wasp start
DATABASE_URL=<url> wasp build
DATABASE_URL=<url> wasp start
But again, this is cumbersome and error-prone. The .env.server file is the best solution. Summary - Add your DATABASE_URL to .env.server in your project root. - Do not rely on setting it inline unless you do so for every command. - This will resolve the Prisma error and allow both wasp build and wasp start to work as expected. If you still see the error after this, double-check that your .env.server file is in the correct location and properly formatted. For more details, see the official docs: Defining Env Vars in Development and Connecting to a Database. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Gwaggli, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Gwaggli
GwaggliOP4w ago
It does not work either. running wasp build works just fine, but wasp build start fails.
Carlos
Carlos4w ago
In wasp build start, you have to explicitly specify which envs you want to pass to the server, through the command line arguments. We did this because we don't want to automatically inherit any arguments, we want you to be explicit so you know which envs to give to your deployment provider.
wasp build start -s DATABASE_URL=my-database-url
wasp build start -s DATABASE_URL=my-database-url
can you try it and tell me if it works?
Gwaggli
GwaggliOP4w ago
Worked like a charm! I ended up using wasp build start --server-env-file .env.server Thank you!! ❤️
Carlos
Carlos4w ago
happy to help, keep wasping on!
martinsos
martinsos4w ago
Great! @Gwaggli , do you think we could have done anything better in the docs / error messages to make this clearer? I do get why it is not obvious without any info, so I wonder if there was a good poitn wher ewe could have provided that info, that would have helped you resolve this on your own.
Gwaggli
GwaggliOP4w ago
@martinsos To be honest i remembered the command from the blog post - so did not check any documentation but could not find it with "build start" search query, and only now saw, that i should have looked under "cli". Probably the best "place" would have been the CLI for me. Print a warning or throw an error if the command is executed without any arguments (or is there a usecase for this scenario)? I just saw that I also could have tried wasp start build --help as the "wrong" argument would have spit out the possible arguments 😄 But hostestly I did not anticipate to use arguments for this, because most wasp commands dont require any. I just tried, saw the error and tried to fix it by defining the env variables directly inside the command instead of using arguments 😄 hope that helps to understand my approach 🙂
martinsos
martinsos4w ago
Yup it does, thanks! I think this is not such an uncommon "path", so others might also hit it. Makes sense to me that in the error message, we give a hint of how to provide the env vars or let you know to not do it the usual way. @Carlos you are the papa of wasp build start, how does this sound to you, should we open GH issue for it? Any ideas on top of it?
Carlos
Carlos4w ago
i think we can create an issue for showing a nudging message when you didn't pass any env vars, that'd be useful!
Carlos
Carlos4w ago
GitHub
wasp build start: Show warning message when no environment variab...
We got a user struggling with wasp build start as they were trying to pass environment variables throught the shell instead of CLI arguments: https://discord.com/channels/686873244791210014/1433736...

Did you find this page helpful?