.env is not readable or not found

hey there I have an API in go and even tho I’ve set up the env’s in Koyeb it still says I don’t have the envs configured even tho its already is configed. im using johoenv this is my code plz help

Hi @RS1,

How and when do you create the .env file?

there is no way to create a .env file on Koyeb as of what I know so I just added my secrets in the Koyeb secretes thingy and I guess its not able to read it from there

Your service is properly getting the environment variables.

I checked your deployment and the code.

The warning you receive is just part of the code when you have .env file.

However, if the DATABASE_URL environment variable was not properly propagated, you would face a fatal error in the logs saying:
DATABASE_URL environment variable not set

So the problem does not come from accessing the variables.

then what could be the problem?

Based on the logs, it seems to be an application failure. So you might need to verify that the service works properly locally and try to troubleshoot if not.

The service works. I’ve tested it on local host too. It works on other hosts too. The thing is code what’s a .env file and render allows it therfore it worked there but I don’t think it works on Koyeb. As yall don’t have file mount.

Coul you share the logs?

It seems that the app start on app.Listen but with no error message. To confirm this you can change your code like this:

diff --git a/main.go b/main.go
index df3add9..dbb6a01 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
 package main
 
 import (
+       "fmt"
        "log"
        "os"
 
@@ -131,5 +132,6 @@ func main() {
 
        // Listen and serve
        port := configuration.GetConfig().Web.Port
-       log.Fatal(app.Listen(":" + port))
+       err = app.Listen(":" + port)
+       log.Fatal(fmt.Sprintf("Failed to start server on port %s: %v", port, err))
 }

Maybe it will tell us more.

Pls add more logs to your app. Without knowing why it fails we cannot help.

im telling you it’s an env error it wants a file mount but Koyeb doesn’t allow to add files in Render (my old host) so like It wants a file as of .env.

You can try this recommendation to create a .env file when starting your service:

whatever ima js add the.env in the code lol

that also didnt work…

Hey,

I managed to reproduce the error locally, and I believe it’s related to the Prefork flag you are using.

I would recommend to test with the flag set to false, and investigate more what’s the issue is.

I was able to reproduce this in a local docker as well, enabling this flag would make the container exit instantly when launched as a pid 1.

I have not much clue on what the underlying issue is, I saw there were a couple of open discussions on fiber, you could also be conflicting with some of your libraries or client that are not compatible.

Please update us if you find something!

Best,

Bastien

Hello there! the issue is now resolved turning off prefork helped it!

This happened to us and was fixed only after full rebuild