dherault / dherault/serverless-offline

Variable Resolution Error When Running Offline Plugin

Open
#1,807 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
5.3k
Forks
811
Avg merge
2d 4h
Merged PRs (30d)
3

Description

## Issue Description

When running the serverless application offline, I encounter the following error:

```
Cannot resolve serverless.yml: Variables resolution errored with:
- Cannot resolve variable at "provider.environment.FOO_BAR": Value not found at "self" source
```

This issue is similar to #1227 (at least with the setup of ENV's), but with a different error message.

## Environment

- Node Version: 20.10.0
- Serverless Version: 3.39.0
- Plugin Version: 13.6.0

## Configuration

Here's my truncated `serverless.yml`:

```yaml
frameworkVersion: "3"

provider:
name: aws
runtime: nodejs20.x
stage: ${opt:stage, self:custom.defaultStage}
profile: ${opt:profile, self:custom.profiles.${self:provider.stage}}
environment:
FOO_BAR: ${self:custom.environmentVariables.${self:provider.stage}.foo.bar}

functions:
siteReviews:
handler: src/siteReviews.handler
events:
- schedule: rate(1 minute)

custom:
defaultStage: "development"
profiles:
development: "redacted-dev"
production: "redacted-prod"
environmentVariables:
production:
foo:
bar: "baz"

plugins:
- serverless-esbuild
- serverless-offline
```

## Attempted Solutions

1. I've tried to manually set the stage to "production" using the `serverless-offline` configuration:

```yaml
custom:
# ... (previous custom configuration)
serverless-offline:
stage: "production"
```

However, I'm still encountering the same error.

2. I discovered that removing `${self:provider.stage}` from the `FOO_BAR` environment variable definition works:

```yaml
provider:
# ... (other provider settings)
environment:
FOO_BAR: ${self:custom.environmentVariables.foo.bar}
```

This suggests that the issue is specifically related to resolving `${self:provider.stage}` when running offline.

## Question

How can I resolve this variable resolution error when running the serverless application offline, particularly when using `${self:provider.stage}` in environment variable definitions?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.