bref icon indicating copy to clipboard operation
bref copied to clipboard

Symfony Dotenv->bootEnv() error

Open eddiejan opened this issue 5 years ago • 8 comments

Hello all,

Since the new releases I'm encoutering issues with loading the environment variables, specifically with Symfony Dotenv.

By following this guide: https://bref.sh/docs/frameworks/symfony.html The Lambda gives us the following errors: image

Not sure why it's looking for the .env file but I assume it has something to do with the recent update on serverless .env file support. https://www.serverless.com/framework/docs/deprecations/#LOAD_VARIABLES_FROM_ENV_FILES

Hope this contributes.

eddiejan avatar Dec 19 '20 13:12 eddiejan

Same here .env is not read by laravel when deployed using sls deploy

shabanbx avatar Dec 19 '20 15:12 shabanbx

Thanks, it seems to be caused by https://github.com/serverless/serverless/pull/8634 (a change in serverless). I'll post a comment there.

mnapoli avatar Dec 19 '20 17:12 mnapoli

If someone else is encountering this problem, you can simply downgrade serverless to 2.15.0 by running the following command and your application should be good to go again: npm install -g [email protected]

eddiejan avatar Dec 19 '20 21:12 eddiejan

If someone else is encountering this problem, you can simply downgrade serverless to 2.15.0 by running the following command and your application should be good to go again: npm install -g [email protected]

Thank you for the quick workaround !

0x346e3730 avatar Dec 19 '20 22:12 0x346e3730

put this in your serverless.yml file

package: include: ".env*"

https://github.com/serverless/serverless/pull/8648#discussion_r546710547

Thanks to @mnapoli they are discussing the .env file as a need for the framework rather than its need for the lambda itself until then the above should work

shabanbx avatar Dec 25 '20 12:12 shabanbx

I think https://github.com/serverless/serverless/pull/8648 solves this issue for now (you need to upgrade serverless), should we close this?

mnapoli avatar Dec 25 '20 20:12 mnapoli

Seems fair right. Maybe update the documentation though?

eddiejan avatar Dec 25 '20 22:12 eddiejan

Serverless 3 enable this behaviour and seems to force it. I had a deprecation saying that I could enable it now and so I did. In order to fix it I had to add a check.

bin/console & public/index.php

- (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
+ if (!isset($_SERVER['LAMBDA_TASK_ROOT'])) (new Dotenv())->bootEnv(dirname(__DIR__).'/.env');

I used the same thing than what's used for cache configuration in src/Kernel.php

vasilvestre avatar Mar 30 '21 07:03 vasilvestre

Closing this issue: .env are no longer excluded by default in SF 3.

mnapoli avatar Dec 01 '22 17:12 mnapoli