如何解决无服务器部署期间出现错误“无法读取未定义的属性‘名称’”
当我运行命令 SLS_DEBUG=* serverless deploy 时,我收到错误 Cannot read property 'name' of undefined
,请帮忙。日志和错误:
Serverless: Load command interactiveCli
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command config:tabcompletion
Serverless: Load command config:tabcompletion:install
Serverless: Load command config:tabcompletion:uninstall
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command upgrade
Serverless: Load command uninstall
Serverless: Load command s3sync
Serverless: Load command s3sync:bucket
Type Error ---------------------------------------------
TypeError: Cannot read property 'name' of undefined
at PluginManager.loadCommands (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:252:51)
at PluginManager.addplugin (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:105:10)
at /usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:121:33
at Array.forEach (<anonymous>)
at PluginManager.loadAllPlugins (/usr/local/lib/node_modules/serverless/lib/classes/PluginManager.js:121:8)
at Serverless.init (/usr/local/lib/node_modules/serverless/lib/Serverless.js:166:30)
at /usr/local/lib/node_modules/serverless/scripts/serverless.js:73:7
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment information ---------------------------
Operating System: darwin
Node Version: 14.15.1
Framework Version: 2.25.2
Plugin Version: 4.4.3
SDK Version: 2.3.2
Components Version: 3.7.0
我的 serverless.yml:
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options,check the docs:
# docs.serverless.com
#
# Happy Coding!
service: blogserverlesstraining
# app and org for use with dashboard.serverless.com
#app: your-app-name
#org: your-org-name
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: 20201221
profile: MyServerlessAccount
region: us-east-1
stage: dev
environment:
tableNamePost: ${self:custom.tableNamePost}
imageUploadBucket: ${self:custom.imagePostsBucket}
region: ${self:provider.region}
cognitoUserPoolClient: XXXXXXXXXXXXXX
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:*
- s3:*
- ses:*
Resource: '*'
plugins:
- serverless-s3-sync
- uuid
custom:
tableNamePost: news
imagePostsBucket: postimagesbucket-123456
functions:
getUser:
handler: lambdas/endpoints/getUser.handler
events:
- http:
path: get-user/{ID}
method: GET
cors: true
getPost:
handler: lambdas/endpoints/getPost.handler
events:
- http:
path: get-post/{ID}
method: GET
cors: true
createPost:
handler: lambdas/endpoints/createPost.handler
events:
- http:
path: create-post
method: POST
cors: true
uploadImage:
handler: lambdas/endpoints/uploadImage.handler
events:
- http:
path: upload-image
method: POST
cors: true
likePost:
handler: lambdas/endpoints/likePost.handler
events:
- http:
path: like-post/{ID}
method: PUT
cors: true
userSignUp:
handler: lambdas/endpoints/userSignUp.handler
events:
- http:
path: sign-up
method: POST
cors: true
confirmSignUp:
handler: lambdas/endpoints/confirmSignUp.handler
events:
- http:
path: confirm-signUp
method: POST
cors: true
userSignIn:
handler: lambdas/endpoints/userSignIn.handler
events:
- http:
path: sign-in
method: POST
cors: true
resources:
Resources:
ImagesPostBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:custom.imagePostsBucket}
MyDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.tableNamePost}
AttributeDeFinitions:
- AttributeName: ID
AttributeType: S
KeySchema:
- AttributeName: ID
KeyType: HASH
BillingMode: PAY_PER_REQUEST
CognitoUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: ${self:provider.stage}-user-pool
UsernameAttributes:
- email
AutoVerifiedAttributes:
- email
Policies:
PasswordPolicy:
MinimumLength: 6
RequireLowercase: False
RequireNumbers: True
RequireSymbols: False
RequireUppercase: True
CognitoUserPoolClient:
Type: AWS::Cognito::UserPoolClient
Properties:
ClientName: ${self:provider.stage}-user-pool-client
UserPoolId:
Ref: CognitoUserPool
ExplicitAuthFlows:
- ADMIN_NO_SRP_AUTH
GenerateSecret: false
解决方法
我相信这可能是 serverless-s3-sync
的一个错误,因为在抛出错误时正在加载这些命令。
我建议删除该插件并重试。如果您需要该插件,您可能需要打开一个错误票 in the repo here
,似乎缺少 serverless-s3-sync
的配置
请查看 serverless-s3-sync
插件的文档以及如何SETUP。
custom:
s3Sync:
# A simple configuration for copying static assets
- bucketName: my-static-site-assets # required
bucketPrefix: assets/ # optional
localDir: dist/assets # required
resources:
Resources:
AssetsBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-static-site-assets
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。