Skip to content

fix(cdk)!: rename DotStack.env to envName for aws-cdk-lib >=2.234.0 compat#7

Merged
shellscape merged 2 commits intoshellscape:masterfrom
hyuntony:fix/cdk/dotstack-env-rename
Apr 27, 2026
Merged

fix(cdk)!: rename DotStack.env to envName for aws-cdk-lib >=2.234.0 compat#7
shellscape merged 2 commits intoshellscape:masterfrom
hyuntony:fix/cdk/dotstack-env-rename

Conversation

@hyuntony
Copy link
Copy Markdown
Contributor

This PR contains a:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes
  • no

Breaking Changes?

  • yes
  • no

Description

In aws-cdk-lib 2.234.0 (released 2026-01-08, via aws/aws-cdk#36599), the parent Stack.env was changed from a writable property to a getter that returns the resolved AWS Environment object ({ account, region }). DotStack's constructor does this.env = env; (where env is the deploy-environment string 'prod'/'dev'/etc.), which now throws:

TypeError: Cannot set property env of [object Object] which has only a getter.

This collision has existed conceptually for a while — DotStack repurposed the parent's env name to mean "deploy-env string" rather than "AWS environment object" — but the runtime didn't surface it until aws-cdk-lib hardened the property descriptor.

Resolution

Rename the deploy-environment string field on DotStack from env to envName, leaving the parent's Stack.env getter unshadowed. After this change:

  • stack.envName returns the deploy-environment string ('prod', 'dev', etc.).
  • stack.env returns the inherited aws-cdk-lib getter ({ account, region }).

All internal call sites that read scope.env as a string have been updated to scope.envName (amplify.ts, dynamo.ts, fargate.ts, function.ts, node-function.ts, signing.ts, ws.ts). This includes two destructured-access patterns (const { env } = scope) in fargate.ts and node-function.ts that would silently break otherwise.

The node.setContext('env', this.envName) call preserves the context key 'env' for backwards compatibility — consumer code reading node.tryGetContext('env') continues to work.

Adjacent dep alignment

Tightened a couple of pre-existing dep mismatches with the new aws-cdk-lib floor while we're here:

  • peerDependencies.aws-cdk-lib: added at ^2.234.0 (was previously dependencies-only; now correctly dedupes with the consumer's CDK install).
  • dependencies.aws-cdk-lib: bumped from ^2.185.0 to ^2.234.0.
  • engines.node: >=18>=20 (matches aws-cdk-lib@2.251.0's engine requirement).
  • constructs: ^10.4.2^10.5.0 (matches aws-cdk-lib@2.251.0's peer requirement).

Happy to split those out if you'd prefer the PR scope to stay strictly on the env rename.

Verification

  • pnpm --filter @dot/cdk build passes (TypeScript compile).
  • pnpm lint clean (one pre-existing warning in security.ts, unrelated).
  • ✅ Smoke-tested: instantiating new DotStack(app, { name: 'smoke' }) with DEPLOY_ENV=prod now succeeds (no TypeError); stack.envName === 'prod'; stack.env returns the parent getter's { account, region }.
  • grep -rn "scope\\.env\\b\\|this\\.env\\b" packages/cdk/src/ empty — no straggling string-env reads.

Migration

A "Migrating from v4 to v5" section has been added to packages/cdk/README.md summarizing the rename and flagging the destructured / template-literal cases that consumers might miss.

BREAKING CHANGES: DotStack.env is renamed to DotStack.envName. Consumer code reading stack.env as a deploy-environment string should be updated to stack.envName. The node.tryGetContext('env') context key is unchanged.

…ompat

In aws-cdk-lib 2.234.0 (PR aws/aws-cdk#36599, released 2026-01-08),
Stack.env was changed from a writable property to a getter returning the
resolved AWS Environment object. DotStack's `this.env = env;` assignment
in the constructor now throws:

  TypeError: Cannot set property env of [object Object] which has only a getter.

Resolution: rename the deploy-environment string field on DotStack to
envName, leaving the parent Stack.env getter unshadowed. After this
change, stack.env returns the AWS { account, region } object and
stack.envName returns the deploy-environment string ('prod', 'dev',
etc.).

All internal call sites that read scope.env as a string have been
updated to scope.envName (dynamo.ts, signing.ts, amplify.ts, function.ts,
node-function.ts, ws.ts).

A peerDependency on aws-cdk-lib >=2.234.0 has been added to enforce
version compatibility, since v5 is incompatible with versions before
2.234.0 (DotStack would set the field but consumers reading
stack.envName would get undefined).

BREAKING CHANGE: DotStack.env is renamed to DotStack.envName. Consumer
code reading stack.env as a deploy-environment string should be updated
to read stack.envName. The node.tryGetContext('env') context key is
unchanged for backward compatibility.
Comment thread packages/cdk/package.json Outdated
{
"name": "@dot/cdk",
"version": "4.2.1",
"version": "5.0.0",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"version": "5.0.0",
"version": "4.2.1",

This is automatic with release tooling.

Comment thread packages/cdk/package.json Outdated
},
"engines": {
"node": ">=18"
"node": ">=20"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"node": ">=20"
"node": ">=22"

Node 20 is end of life in 3 days

Copy link
Copy Markdown
Contributor Author

@hyuntony hyuntony Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image Happy to make this change, I was matching the aws-cdk-lib's engine requirements here

Comment thread packages/cdk/package.json Outdated
"peerDependencies": {
"@swc-node/register": "^1.5.4",
"@swc/core": "^1.3.5",
"aws-cdk-lib": "^2.234.0",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"aws-cdk-lib": "^2.234.0",

It's already a direct dependency

- Revert version to 4.2.1 (release tooling auto-bumps from breaking
  commit marker; see @dot/versioner)
- Bump engines.node from >=20 to >=22 (Node 20 EOL imminent)
- Drop aws-cdk-lib peerDependencies entry (already a direct dependency)
- Trim README sentence referencing the removed peerDep

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@shellscape shellscape merged commit 24ab4cc into shellscape:master Apr 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants