AWS CDK执行命令时遭遇stack.regionalFact函数不存在错误的求助
stack.regionalFact is not a function Error in AWS CDK 1.121.0 This error almost always stems from version mismatches between AWS CDK packages—specifically, when @aws-cdk/aws-iam (which calls stack.regionalFact) relies on a method that's missing in your installed version of @aws-cdk/core. Here's how to fix it:
Step 1: Ensure All CDK Packages Share the Exact Same Version
AWS CDK requires all @aws-cdk/* packages to be on the same version to maintain compatibility.
- Open your
package.jsonfile and check every entry starting with@aws-cdk/(e.g.,@aws-cdk/core,@aws-cdk/aws-lambda,@aws-cdk/aws-iam,@aws-cdk/aws-appsync). Make sure all of them are set to1.121.0. - If any packages have different versions, update them to match. For example:
{ "dependencies": { "@aws-cdk/core": "1.121.0", "@aws-cdk/aws-lambda": "1.121.0", "@aws-cdk/aws-iam": "1.121.0", "@aws-cdk/aws-appsync": "1.121.0", // other dependencies... } } - Clean your existing dependencies and reinstall to ensure consistency:
# Delete node_modules and lock file rm -rf node_modules package-lock.json # Reinstall dependencies npm install
Step 2: (Alternative) Upgrade to a More Stable 1.x CDK Version
Version 1.121.0 is relatively old and has known compatibility quirks. The 1.x line of CDK ended with version 1.199.0—upgrading to this version can resolve many such bugs:
- Upgrade the global CDK CLI:
npm install -g aws-cdk@1.199.0 - Upgrade your project's CDK dependencies:
npm install @aws-cdk/core@1.199.0 @aws-cdk/aws-lambda@1.199.0 @aws-cdk/aws-iam@1.199.0 @aws-cdk/aws-appsync@1.199.0 - Clean and reinstall dependencies as in Step 1.
Step 3: Verify the Fix
After completing either step above, try running your cdk deploy command again. The error should be resolved, and your Lambda function should deploy successfully alongside your AppSync API.
内容的提问来源于stack exchange,提问作者Muhammad Muaz

