Skip to content
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

version 6.7.0 offline: Failure: Cannot read property 'defineService' of undefined #1075

Closed
coolboy0961 opened this issue Aug 27, 2020 · 8 comments

Comments

@coolboy0961
Copy link

coolboy0961 commented Aug 27, 2020

Bug Report

Current Behavior
When I version up serverless-offline from 6.6.0 to 6.7.0, and I perform API testing, I start to get the following error.
Everything is ok in 6.6.0.

offline: GET /local/api/v1/session (λ: session)
offline: Failure: Cannot read property 'defineService' of undefined
TypeError: Cannot read property 'defineService' of undefined
    at Object.<anonymous> (/Users/chenj49/git/git_gs-failure-relief-pack/backend/node_modules/aws-sdk/clients/sts.js:7:19)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/Users/chenj49/git/git_gs-failure-relief-pack/backend/node_modules/aws-sdk/lib/credentials/temporary_credentials.js:2:11)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/Users/chenj49/git/git_gs-failure-relief-pack/backend/node_modules/aws-sdk/lib/node_loader.js:32:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/Users/chenj49/git/git_gs-failure-relief-pack/backend/node_modules/aws-sdk/clients/all.js:1:1)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/Users/chenj49/git/git_gs-failure-relief-pack/backend/.build/src/nonfunctional/notification.js:43:13)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/Users/chenj49/git/git_gs-failure-relief-pack/backend/.build/handler.js:45:22)
    at Module._compile (internal/modules/cjs/loader.js:776:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at /Users/chenj49/git/git_gs-failure-relief-pack/backend/node_modules/serverless-offline/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js:80:133
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at InProcessRunner.run (/Users/chenj49/git/git_gs-failure-relief-pack/backend/node_modules/serverless-offline/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js:80:9)

Sample Code
my command to start serverless offline.

serverless offline --stage local start

Environment

  • serverless version: [v1.79.0]
  • serverless-offline version: [v6.7.0]
  • node.js version: [v12.6.0]
  • OS: [macOS 10.14.6]
@tdfacer
Copy link

tdfacer commented Aug 28, 2020

I'm running into this same issue today running similar versions and a similar start command:

  • start command: sls offline --stage local --prefix=<my_service_name>
  • serverless - v1.80.0
  • serverless-offline - v6.7.0
  • node.js - 12.x
  • OS - Arch Linux

@kdybicz
Copy link
Contributor

kdybicz commented Aug 28, 2020

Got the same issue, downgrading to 6.6.0 resolved my problem temporarily.

Note: All works fine for first request, above error pops up on second and each next one.

serverless - 1.81.0
serverless-offline - v6.7.0
aws-sdk - 2.741.0
node.js - 14.8.0
OS - macOS 10.15.6

@coolboy0961
Copy link
Author

coolboy0961 commented Aug 28, 2020

I found the way to fix this problem.

Just add following settings into your serverless.yml

custom:
  serverless-offline:
    allowCache: true

I found the changes of v6.6.0 → v6.7.0
The default option will clear global variables every time when handler is called, I am using aws-sdk, there are some global variables in this node module.
I think they become to undefined, and occurs this issue.

@kdybicz
Copy link
Contributor

kdybicz commented Aug 28, 2020

I'm not sure if this ticket should be closed. By default - without allowCache: true being set - my app is crashing. I don't think that should be default behaviour. There needs to be a better fix for that problem or allowCache should be default be true.

@tdfacer
Copy link

tdfacer commented Aug 28, 2020

Adding the allowCache: true option to serverless did not solve the problem for me, but installing a specific combination of aws-sdk, serverless-offline, and serverless packages allowed me to work around the issue. Here are the commands I used in my project that finally ended up working:

  • yarn remove aws-sdk serverless serverless-offline
  • yarn add -D serverless@^1.78.1 serverless-offline@6.5.0 aws-sdk@^2.741.0

@micheleangioni
Copy link

I've been hit by this process as well. I look forward to having a definitive solution! :)

@kdybicz
Copy link
Contributor

kdybicz commented Sep 17, 2020

At this moment I can only recommend downgrading to v6.6.0

@BrendanEthika
Copy link

For me it was missing handler: handler.run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants