5

I am unable to load env files located in a custom path using serverless framework.

The env files are kept in a folder 'config/environment' in the project and the files available are

  • .env
  • .env.dev
  • .env.qa
  • .env.prod

The contents of Serverless.yml are as below

plugins:
   - serverless-dotenv-plugin
custom:
  stage: ${opt:stage, "dev"}
  dotenv:
    basePath: ./config/environment/
    logging: false

While triggering 'serverless deploy', I get error as below

Cannot resolve serverless.yml: Variables resolution errored with:

  • Cannot resolve variable at "provider.xxxxxx": Value not found at "env" source,
  • Cannot resolve variable at "provider.xxxxxx": Value not found at "env" source,
  • Cannot resolve variable at "provider.xxxxxx": Value not found at "env" source,
  • Cannot resolve variable at "provider.xxxxxx": Value not found at "env" source,
  • Cannot resolve variable at "provider.xxxxxx": Value not found at "env" source,

It seems the .env files are not getting loaded and any help will be appreciated.

Adarsh
  • 177
  • 1
  • 13

2 Answers2

0

I have the same problem. The problem happend when I update serverless framework v3 from v2. If I don't use basePath or path and move .env, .env.prod to root folder it works, but I hope to have better solution.

Seokhyon
  • 1
  • 1
0

Here

dotenv: {
  path: 'config/${self:provider.stage}/.env',
},