I am using serverless framework to deploy react web application. I’ve set up a CI/CD pipeline for deployment. when serverless template gets executed I am receiving several deprecation warnings.
Serverless: Deprecation warning: Detected ".env" files. In the next major release variables from ".env" files will be automatically loaded into the serverless build process. Set "useDotenv: true" to adopt that behavior now. More Info: https://www.serverless.com/framework/docs/deprecations/#LOAD_VARIABLES_FROM_ENV_FILES Serverless: Deprecation warning: Variables resolver reports following resolution errors: - Cannot resolve variable at "provider.profile": Value not found at "env" source From a next major this will be communicated with a thrown error. Set "variablesResolutionMode: 20210326" in your service config, to adapt to new behavior now More Info: https://www.serverless.com/framework/docs/deprecations/#NEW_VARIABLES_RESOLVER
The way I understand these warnings, it is trying to load environment variables from .env file from the serverless directory. But I’ve stored my variables from other files(abc.config) and loading them to the serverless template through that file and not from the .env file. and for this reason I am getting these warnings.
Also I’ve used
serverless-dotenv-plugin to use environment variables in .env file for local deployment and that’s why the .env file has to be there in the serverless directory. But for now loading variables from abc.config file is working fine and in the future, I want to load variables from the same file(abc.config). But in the future, if I use the same approach for environment variables, that will throw an error instead of giving a warning.
Questions 1: I am not sure how would I tackle this issue. because in the upcoming serverless version release this will throw an error.
Question 2: What if I install a specific serverless version. for example; npm install -g email@example.com in that case, in the future will I still get these deprecation warnings? In theory, I’ll be still using the old serverless version and this version supports loading variables from other files. So I should not be getting these warnings. I can be wrong. but what should be the ideal approach to resolve these warnings ahead of time?
Any help would be greatly appreciated.