thebarndog / swift-dotenv

Swift micro-package for loading .env environment files
MIT License
29 stars 8 forks source link

Throwing Exception When Calling DotEnv.configure #25

Open azamsharpschool opened 1 month ago

azamsharpschool commented 1 month ago

Dotenv.configure() is throwing exception

Fatal error: 'try!' expression unexpectedly raised an error: SwiftDotenv.Dotenv.LoadingFailure.environmentFileIsMissing

even though I have a file called .env with keys and values.

thebarndog commented 4 weeks ago

@azamsharpschool what's the location of your .env file? The default path is .env but your file might not be located there. Assuming that you're developing a script? If you're developing for an iOS application or another platform, then you'll have change the default file path from .env to wherever the file lives but then you'll have to include the file in your app bundle which defeats the purpose of using this library in the first place.

I think it's not clear from the README and I can update it because this isn't the first time it's come up but this library is for scripting only when using in conjunction with a .env file. If you just want to read environment values from the underlying process, you can (it just proxies to processInfo.environment) but loading a .env file into an application would mean you have to include it in your bundle and in your version control.

minsoe commented 3 weeks ago

So, where should we put this .env file iOS? the same location as Xcode project file?

thebarndog commented 2 weeks ago

No, you don't use .env files for iOS applications; it's for scripting only. Think about it, it doesn't make sense. In order for the iOS application to be able to see the environment file, it would have to be included in the bundle. And even if you manage to keep it out of version control, you're still loading that file into the application bundle that gets distributed to users.