localstack / serverless-localstack

⚡ Serverless plugin for running against LocalStack
511 stars 82 forks source link

TypeError: Cannot read property 'console' of undefined in deploy/index.js #180

Closed noudadrichem closed 1 year ago

noudadrichem commented 2 years ago

Hi, I created this issue on https://github.com/serverless/serverless/issues/10770 but high chance it's related to this.

Are you certain it's a bug?

Is the issue caused by a plugin?

Are you using the latest version?

Is there an existing issue for this?

Issue description

tl;dr: Either the rest API and SQS worker examples give an error when deploying to localstack.

I'm following the documentation to test out serverless with LocalStack. I'm using the serverless command to init a starter project.

I'm using this tutorial to add deployment to localstack: https://www.serverless.com/plugins/serverless-localstack

What I get back is this stdout: (I added this to the issue)

I'm unsure if this is plugin issue or not as the file the error occurs in is lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:169:31) where it clearly says this.console but it is not defined in the class code.

Service configuration (serverless.yml) content

service: aws-node-sqs-worker-project
frameworkVersion: '3'

provider:
  name: aws
  runtime: nodejs14.x

plugins:
  - serverless-localstack
  - serverless-lift

custom:
  localstack:
    stages:
      # list of stages for which the plugin should be enabled
      - local
    host: http://localhost  # optional - LocalStack host to connect to
    edgePort: 4566  # optional - LocalStack edge port to connect to
    autostart: true  # optional - Start LocalStack in Docker on Serverless deploy
    lambda:
      # Enable this flag to improve performance
      mountCode: True
    docker:
      # Enable this flag to run "docker ..." commands as sudo
      sudo: False
  stages:
    local:

constructs:
  jobs:
    type: queue
    worker:
      handler: handler.consumer

functions:
  producer:
    handler: handler.producer
    events:
      - httpApi:
          method: post
          path: /produce
    environment:
      QUEUE_URL: ${construct:jobs.queueUrl}

Command name and used flags

serverless deploy --stage local

Command output

Using serverless-localstack

Deploying aws-node-sqs-worker-project to stage local (us-east-1)
Skip plugin function Package.packageService (lambda.mountCode flag is enabled)
Skip plugin function AwsCompileFunctions.downloadPackageArtifacts (lambda.mountCode flag is enabled)
Skip plugin function AwsDeploy.extendedValidate (lambda.mountCode flag is enabled)

✖ Stack aws-node-sqs-worker-project-local failed to deploy (5s)
Environment: darwin, node 14.18.2, framework 3.4.0, plugin 6.1.2, SDK 4.3.1
Credentials: Local, environment variables
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
TypeError: Cannot read property 'console' of undefined
    at aws:deploy:deploy:checkForChanges (/Users/nowed/.nvm/versions/node/v14.18.2/lib/node_modules/serverless/lib/plugins/aws/deploy/index.js:169:31)
    at async PluginManager.runHooks (/Users/nowed/.nvm/versions/node/v14.18.2/lib/node_modules/serverless/lib/classes/plugin-manager.js:530:9)
    at async PluginManager.invoke (/Users/nowed/.nvm/versions/node/v14.18.2/lib/node_modules/serverless/lib/classes/plugin-manager.js:564:9)
    at async PluginManager.spawn (/Users/nowed/.nvm/versions/node/v14.18.2/lib/node_modules/serverless/lib/classes/plugin-manager.js:585:5)
    at async PluginManager.runHooks (/Users/nowed/.nvm/versions/node/v14.18.2/lib/node_modules/serverless/lib/classes/plugin-manager.js:530:9)
    at async PluginManager.invoke (/Users/nowed/.nvm/versions/node/v14.18.2/lib/node_modules/serverless/lib/classes/plugin-manager.js:564:9)
    at async PluginManager.run (/Users/nowed/.nvm/versions/node/v14.18.2/lib/node_modules/serverless/lib/classes/plugin-manager.js:604:7)
    at async Serverless.run (/Users/nowed/.nvm/versions/node/v14.18.2/lib/node_modules/serverless/lib/serverless.js:174:5)
    at async /Users/nowed/.nvm/versions/node/v14.18.2/lib/node_modules/serverless/scripts/serverless.js:687:9

Environment information

serverless --version                                                                                                                             
Framework Core: 3.4.0
Plugin: 6.1.2
SDK: 4.3.1
rasmusfahnoe commented 2 years ago

Experiencing the exact same issue, only occurs when mountCode: true.

brennan-karrer commented 2 years ago

Confirmed the above. This is only happening when mountCode: true is set.

mkkurt commented 2 years ago

It happens to me too when mountCode: true is set.

juha-younite commented 2 years ago

Also confirming, that it happens when mountCode: true is set.

The reason for that is that for some reason this.state is not defined in line 169 } else if (this.state.console) {

berlinger-ciprianpetrisor commented 2 years ago

Confirming as well. This seems to be a recent addition in severless, related to aws console support in release 3.4.0 (2022-02-25). Downgrading to 3.3.0 fixed the issue for me.

samwiseduzer commented 2 years ago

This still seems to be an issue in Serverless 3.17

whummer commented 2 years ago

Hi @noudadrichem @rasmusfahnoe @samwiseduzer @berlinger-ciprianpetrisor @juha-finlabs @mkkurt @brennan-karrer , thanks for reporting. We have now pushed a new version serverless-localstack@0.4.36 with a small fix - can you please try upgrading and confirm if the issue is resolved with the latest version? Thanks!

whummer commented 1 year ago

Closing this as resolved. Please let us know if the problem persists.. Thanks!