-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(cli): TypeError: localAspects is not iterable #32470
Comments
This seems likely to have been caused by #32097 @sumupitchayan |
Most likely caused here which was implemented as part of PR #32097 as @nmussy mentioned in #32470 (comment). Below sample CDK code using Aspects doesn't reproduce the issue (used CDK version class BucketVersioningChecker implements cdk.IAspect {
public visit(node: IConstruct): void {
// See that we're dealing with a CfnBucket
if (node instanceof s3.CfnBucket) {
// Check for versioning property, exclude the case where the property
// can be a token (IResolvable).
if (!node.versioningConfiguration
|| (!cdk.Tokenization.isResolvable(node.versioningConfiguration)
&& node.versioningConfiguration.status !== 'Enabled')) {
cdk.Annotations.of(node).addError('Bucket versioning is not enabled');
}
}
}
}
// Later, apply to the stack
cdk.Aspects.of(stack).add(new BucketVersioningChecker()); Taking example from Applying Aspects with Priority also works fine: import * as cdk from 'aws-cdk-lib';
import * as s3 from 'aws-cdk-lib/aws-s3';
const app = new cdk.App();
const stack = new CdktestStackNew(app, 'CdktestStackNew', {
env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION },
});
class CdktestStackNew extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new s3.Bucket(this, 'TestBucket')
}
}
class MyAspect implements cdk.IAspect {
visit(node: IConstruct) {
// Modifies a resource in some way
if (node instanceof s3.CfnBucket) {
node.versioningConfiguration = {
status: 'Enabled'
};
}
}
}
class ValidationAspect implements cdk.IAspect {
visit(node: IConstruct) {
// Perform some readonly validation on the construct tree
if (node instanceof s3.CfnBucket) {
// Check for versioning property, exclude the case where the property
// can be a token (IResolvable).
if (!node.versioningConfiguration
|| (!cdk.Tokenization.isResolvable(node.versioningConfiguration)
&& node.versioningConfiguration.status !== 'Enabled')) {
cdk.Annotations.of(node).addError('Bucket versioning is not enabled');
}
}
}
}
// Later, apply to the stack
cdk.Aspects.of(stack).add(new MyAspect(), { priority: cdk.AspectPriority.MUTATING } ); // Run first (mutating aspects)
cdk.Aspects.of(stack).add(new ValidationAspect(), { priority: cdk.AspectPriority.READONLY } ); // Run later (readonly aspects) @github2023spring Good afternoon. Could you please share minimal reproducible CDK code to reproduce the issue? |
i haven't been able to reproduce on a small scale, but i've got the same issue... |
could you give any more information on what i might be looking for? afaik i don't use these "Aspects" in my code, it's all under-the-hood for me. |
Same, I am not sure how to reproduce it without sharing the actual production code. |
i do some kinda weird stuff with stacks here: https://github.com/shepherd-media-classifier/shepherd/blob/master/app.ts |
@rosmcmahon thanks your GitHub repo is very helpful. Is the |
|
@rosmcmahon what command do you run on your repo to reproduce this error? |
I can't even get it to synth
Looks like this repo needs a just-so setup. |
I ripped out all the synth-time SSM lookups and upgraded to
I wonder if the node version has anything to do with it?
|
I don't understand how this can happen. The relevant bits of code look like this (from unminified JS to make sure it's not transpilation gone awry): class Aspects {
get applied() {
return [...this._appliedAspects]
}
}
/////////////////////////////
let aspects = aspect_1().Aspects.of(construct);
let localAspects = aspects.applied;
const allAspectsHere = sortAspectsByPriority(inheritedAspects, localAspects),
///////////////////////////
function sortAspectsByPriority(inheritedAspects, localAspects) {
return [...inheritedAspects, ...localAspects].sort(...) // <-- boom here
} I don't understand how this can in any way lead to |
Oooooooooohhhhhhhhhh I think you might have multiple copies of In those cases, if you get an |
I'm encountering the same error and all the versions of
|
Any locally symlinked packages on your machine? |
No, everything seems fine on that front. |
Closes #32470 ### Reason for this change Some customers have reported seeing the error `TypeError: localAspects is not iterable` upon upgrading to CDK v2.172.0 (this is when the Priority-ordered aspects feature was released). This is likely caused by customers having dependencies on third-party constructs/libraries which are using outdated versions (< 2.172.0) of CDK. The problem more specifically is that the `Aspects.applied` function was added in v2.172.0, and the new `invokeAspects` function calls this function on all nodes in the tree. ### Description of changes Created a workaround for customers. Added the `getAspectApplications` function in `synthesis.ts` - this function creates `AspectApplication` objects from `Aspects.all` if `Aspects.applied` does not exist. ### Describe any new or updated permissions being added None. ### Description of how you validated changes New unit test in `aspect.test.ts` with a monkey patched `Aspects.applied` function. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Comments on closed issues and PRs are hard for our team to see. |
Closes #32470 ### Reason for this change Some customers have reported seeing the error `TypeError: localAspects is not iterable` upon upgrading to CDK v2.172.0 (this is when the Priority-ordered aspects feature was released). This is likely caused by customers having dependencies on third-party constructs/libraries which are using outdated versions (< 2.172.0) of CDK. The problem more specifically is that the `Aspects.applied` function was added in v2.172.0, and the new `invokeAspects` function calls this function on all nodes in the tree. ### Description of changes Created a workaround for customers. Added the `getAspectApplications` function in `synthesis.ts` - this function creates `AspectApplication` objects from `Aspects.all` if `Aspects.applied` does not exist. ### Describe any new or updated permissions being added None. ### Description of how you validated changes New unit test in `aspect.test.ts` with a monkey patched `Aspects.applied` function. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Please add your +1 👍 to let us know you have encountered this
Status: IN-PROGRESS
Overview:
Users who run into this issue have multiple copies of aws-cdk-lib in your dependency tree at different versions. For example using a construct library that directly depends on a different aws-cdk-lib version, or from local symlinking multiple workspace directories together (npm link), or a messy npm install history.
In those cases, if you get an Aspects object from an older aws-cdk-lib version, then aspects.applied would return undefined which definitely is not iterable!
Complete Error Message:
Workaround:
Downgrade to CDK v2.171.1, Rolling forward to CDK v2.173.3 when released, or fixing the dependency issue in your CDK app.
Solution:
#32647
Related Issues:
Original Issue:
Describe the bug
After updating to 2.172.0, the cdk synth command produce the following error message.
Regression Issue
Last Known Working CDK Version
2.171.1
Expected Behavior
cdk synth should produce cloudformation template
Current Behavior
cdk synth failed
Reproduction Steps
Updating to 2.172.0, and run cdk synth.
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.172.0
Framework Version
No response
Node.js Version
v20.18.1
OS
MacOs
Language
TypeScript
Language Version
5.7.2
Other information
No response
The text was updated successfully, but these errors were encountered: