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

TypeError: Cannot read property 'handler' of undefined #143

Open
thg303 opened this issue Apr 15, 2021 · 5 comments · May be fixed by #151
Open

TypeError: Cannot read property 'handler' of undefined #143

thg303 opened this issue Apr 15, 2021 · 5 comments · May be fixed by #151

Comments

@thg303
Copy link

thg303 commented Apr 15, 2021

I install the plugin using:
serverless plugin install --name serverless-mocha
when I try to create a function like this:
sls create function -f testFunction --handler src/functions/testFunction.testFunction -p src/tests/

I get the following result:

Serverless: Deprecation warning: CLI options definitions were upgraded with "type" property (which could be one of "string", "boolean", "multiple"). Below listed plugins do not predefine type for introduced options:
             - mochaPlugin for "function", "path", "handler", "httpEvent", "reporter", "reporter-options", "grep", "live", "root", "compilers", "timeout", "exit"
            Please report this issue in plugin issue tracker.
            Starting with next major release, this will be communicated with a thrown error.
            More Info: https://www.serverless.com/framework/docs/deprecations/#CLI_OPTIONS_SCHEMA
Serverless: Generating function...
Serverless: Created function file "/Users/ali/projects/serverless-crm/src/functions/testFunction.js"

 Type Error ----------------------------------------------

  TypeError: Cannot read property 'handler' of undefined
      at mochaPlugin.createTest (/Users/ali/projects/serverless-crm/node_modules/serverless-mocha/index.js:367:31)
      at PluginManager.invoke (/Users/ali/.nvm/versions/node/v14.16.1/lib/node_modules/serverless/lib/classes/PluginManager.js:551:20)

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  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.16.1
     Framework Version:         2.35.0
     Plugin Version:            4.5.3
     SDK Version:               4.2.2
     Components Version:        3.8.3

It creates the function file at src/functions/testFunction.testFunction.js but the serverless.yaml file changes are:

  undefined:
    handler: src/functions/testFunction.testFunction

and no test file is generated.

@mjoey
Copy link

mjoey commented Apr 20, 2021

Hi,
Use the 1.83.0 serverless version.
npm install -g serverless@1.83.0
Best

@thg303
Copy link
Author

thg303 commented Apr 21, 2021

It's Strange, but I managed to make it work by using --function instead of -f like this:

sls create function --function testFunction --handler src/functions/testFunction.testFunction -p src/tests/

@mjoey
Copy link

mjoey commented Apr 23, 2021

Yes it works :)
Great!

@medikoo medikoo linked a pull request Aug 17, 2021 that will close this issue
@medikoo
Copy link

medikoo commented Aug 17, 2021

Should be fixed with #151

@tdi this plugin seems to miss types for CLI options it defines, such functionality was at some point added with v2 of Serverless Framework, and is scheduled to be mandatory in v3. Is there any chance to have mentioned PR merged and published?

@ashen780dimo
Copy link

ashen780dimo commented Aug 19, 2021

I'm having the same issue when using -f but sls create function --function testFunction --handler src/functions/testFunction.testFunction -p src/tests/ works.

Your Environment Information ---------------------------
Operating System: win32
Node Version: 14.15.4
Framework Version: 2.55.0
Plugin Version: 5.4.3
SDK Version: 4.2.6
Components Version: 3.15.1

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

Successfully merging a pull request may close this issue.

4 participants