首页 > 解决方案 > 无服务器部署期间出现错误“无法读取未定义的属性‘名称’”

问题描述

当我运行命令 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

标签: node.jsnode-modulesserverless-frameworkserverlessaws-serverless

解决方案


我相信这可能是一个错误serverless-s3-sync,因为在引发错误时正在加载这些命令。

我建议删除该插件并重试。如果您需要该插件,您可能需要在此处的 repo中打开错误票


推荐阅读