serverless-webpack: No matching handler found for 'handler'. Check your service definition

I just upgraded from serverless-webpack 2.0.0 to 2.2.0 and got the following error. It was working perfectly with the previous version.

No matching handler found for 'handler'. Check your service definition

Is there anything wrong in my configuration?

service: my_service

provider:
  ...

custom:
  webpack: webpack.config.serverless.js

functions:
  my_function:
    handler: handler.my_function
    events:
       ...

plugins:
  - serverless-webpack

FYI I’m on serverless latest (as of today: 1.18.1)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 23 (13 by maintainers)

Most upvoted comments

Ok, found. The problem is that slsw.lib.entries does not contain an array, but the object { 'src/server/handler': './src/server/handler.js' }

If I just use the previous config, it works fine

module.exports = {
  entry: ['./src/server/handler.js']

So, at the end, the fix was to set the path in the handler definition:

functions:
  my_function:
    handler: src/server/handler.my_function

Ok. I think the missing path in the function definition is the problem. The function definition should define the path - otherwise you’d also get issues with other plugins that need to find the handler. The problem is, that Serverless (the framework) is completely unaware of the handler location in your case.

So, please change the handler definition in your serverless.yml.

… and the good thing: With 2.2.0 you now do not have to set the entries manually anymore in your webpack config. Just use:

// webpack.conf.js
const slsw = require('serverless-webpack');
module.exports = {
  entry: slsw.lib.entries,
  ...
  output: {
    ...
    filename: '[name].js',
    ...
  }
};

Then you can add functions to your service without changing the config again.

@HyperBrain thanks again for your help.

I’ve experimented further, using your v3.0.0-individual-packaging branch and serverless-plugin-optimize. Here’s the repo.

Adding the plugin does reduce the time to deploy, but once deployed the Lambda errors with:

module initialization error: Error
    at s (/var/task/_optimize/service-name-dev-hello/src/handler.js:1:683)
    at /var/task/_optimize/service-name-dev-hello/src/handler.js:1:734
    at Object.309../utils (/var/task/_optimize/service-name-dev-hello/src/handler.js:86857:174)
    at s (/var/task/_optimize/service-name-dev-hello/src/handler.js:1:683)
    at /var/task/_optimize/service-name-dev-hello/src/handler.js:1:734
    at Object.308../hello (/var/task/_optimize/service-name-dev-hello/src/handler.js:86854:80)

It’s probably that my configuration with serverless-plugin-optimize is incorrect. Will try to get it working.

Hope that’s useful 😬

@HyperBrain thanks for all your help! I have a working set-up now:

const nodeExternals = require("webpack-node-externals");
const slsw = require("serverless-webpack");
const path = require("path");

module.exports = {
  entry: slsw.lib.entries,
  target: "node",
  externals: [nodeExternals()],
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        use: [
          {
            loader: "babel-loader",
            options: {
              presets: ["node6", "stage-0"],
              plugins: []
            }
          }
        ]
      }
    ]
  },
  output: {
    libraryTarget: "commonjs2",
    path: path.join(__dirname, ".webpack"),
    filename: "[name].js"
  }
};

and followed your suggestion of using webpack ^3.0.0 as a dependency.

I’ll reach out to the maintainer of serverless-babel-starter and see if they’re open to a PR 👍

Thanks again!

Glad to hear that it now works 👍

By the way, I’m using yarn to freeze dependencies. I noticed while trying several configurations that I can get the issue with 2.0.0 too. It looks like the problem appears with the upgrade of an inner dependency, somewhere.