Skip to content

Conversation

@brendan-smp
Copy link
Contributor

Summary

  • Fixes Vpc.get() failing with ReferenceError: Cannot access 'natInstances' before initialization when referencing a VPC created with bastion: true

Problem

When using sst.aws.Vpc.get() to reference an existing VPC that was created with bastion: true, deployment fails with:

ReferenceError: Cannot access 'natInstances' before initialization

Root Cause

In platform/src/components/aws/vpc.ts, the registerOutputs() function references the local variable natInstances instead of the class property self.natInstances.

When using Vpc.get() (the ref path, lines 370-386), registerOutputs() is called at line 385, but the local const natInstances = createNatInstances(); is only defined at line 401 (after the ref code path returns).

In the ref path, this.natInstances is properly set from ref.natInstances, but the registerOutputs() function incorrectly references the local variable instead of the class property.

Fix

Change natInstances to self.natInstances in the registerOutputs() function (line 693).

Fixes #6346

This is a regression from #5820

…ith bastion

When using Vpc.get() to reference an existing VPC created with bastion: true,
deployment fails with "Cannot access 'natInstances' before initialization".

The registerOutputs() function incorrectly references the local variable
`natInstances` instead of the class property `self.natInstances`. In the ref
path (Vpc.get), registerOutputs() is called before the local variable is
defined, but the class property is already set from ref.natInstances.

Fixes anomalyco#6346

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jamesgibbons92
Copy link
Collaborator

jamesgibbons92 commented Jan 21, 2026

I think I resolved this in #6341 already. But I will ping Frank to merge this as it's smaller and fixes the immediate issue.

@fwang fwang merged commit 8b60ff4 into anomalyco:dev Jan 22, 2026
@brendan-smp brendan-smp deleted the fix/vpc-get-nat-instances branch January 22, 2026 03:17
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.

Vpc.get() fails with "Cannot access 'natInstances' before initialization" (regression in v3.17.26)

3 participants