question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

5.3.0: Handler 'handler' missing on module

See original GitHub issue

This is a (Bug Report / Feature Proposal)

Bug Report

Description

For bug reports:

  • What went wrong? Upgrading from 5.2.0 to 5.3.0 causes Lambda to not recognize exports.handler within the webpack generated Lambda function. Upon upgrading and running sls deploy, a Lambda function with an import statement will return the following error:

Handler ‘handler’ missing on module

Upon rolling back to 5.2.0 and another sls deploy, the handler is recognized again.

  • What did you expect should have happened? The packager should not obscure exports.handler.

  • What was the config you used?

package.json

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "private": true,
  "workspaces": [
    "src/lib/*"
  ],
  "sideEffects": false,
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.4.3",
    "@babel/preset-env": "^7.4.3",
    "aws-sdk": "^2.437.0",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "^10.0.1",
    "babel-loader": "^8.0.4",
    "babel-plugin-source-map-support": "^2.0.1",
    "babel-polyfill": "^6.26.0",
    "eslint": "^5.16.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-plugin-import": "^2.17.1",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-prettier": "^3.0.1",
    "eslint-plugin-react": "^7.12.4",
    "prettier": "^1.17.0",
    "progress-bar-webpack-plugin": "^1.12.1",
    "serverless-plugin-split-stacks": "^1.7.2",
    "serverless-webpack": "^5.2.0",
    "terser-webpack-plugin": "^1.2.3",
    "webpack": "^4.30.0",
    "webpack-cli": "^3.2.3"
  },
  "dependencies": {
    "crypto-secure-random-digit": "^1.0.7",
    "serverless-appsync-plugin": "^1.1.0",
    "serverless-plugin-aws-alerts": "^1.2.4",
    "source-map-support": "^0.5.12"
  }
}

webpack.config.js

const path = require("path");
const webpack = require("webpack");
const slsw = require("serverless-webpack");
const TerserPlugin = require("terser-webpack-plugin");
const ProgressBarPlugin = require("progress-bar-webpack-plugin");

const handler = (percentage, message, ...args) => {
  // e.g. Output each progress message directly to the console:
  console.info(percentage, message, ...args);
};

module.exports = {
  mode: "development",
  entry: slsw.lib.entries,
  target: "node",
  devtool: "none",
  externals: [
    {
      "aws-sdk": "commonjs aws-sdk",
      bufferutil: "commonjs bufferutil",
      "utf-8-validate": "commonjs utf-8-validate"
    }
  ],
  plugins: [
    new ProgressBarPlugin(),
    new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
  ],
  optimization: {
    minimizer: [new TerserPlugin({ parallel: true, sourceMap: false })], // sourceMap: true
    minimize: false,
    usedExports: true
  },
  performance: {
    hints: false
  },
  stats: {
    maxModules: Infinity,
    optimizationBailout: false
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        loader: "babel-loader",
        include: path.resolve(__dirname, "src/services"),
        sideEffects: false,
        options: {
          babelrc: false,
          presets: [
            [
              "@babel/preset-env",
              {
                targets: {
                  node: "8.10"
                },
                shippedProposals: true,
                modules: false,
                debug: false
              }
            ]
          ]
        }
      }
    ]
  }
};

from serverless.json

webpack:
    packager: "yarn"
    webpackConfig: "./webpack.config.js"
  • What stacktrace or error message from your provider did you see?

Handler ‘handler’ missing on module

Additional Data

The problem only seems to arise with lambda functions using import. If the function does not contain an import, it seems to be understood by Lambda (it finds the handler). I created a simple test function and packaged two versions of it using 5.3.0. One has an import, the other does not. The imported file is also very simplistic and just contains a console.log(). Here is a selection of the generated output from each:

without import:

function(module, __webpack_exports__, __webpack_require__) {
        "use strict";
        __webpack_require__.r(__webpack_exports__);
        /* harmony import */ var test__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
          /*! test */ "./src/lib/test/index.js"
        );
        exports.handler = async event => {
          console.log(JSON.stringify(event)); // const { userId } = event;
        };

        /***/
      }

with import

(function(module, __webpack_exports__, __webpack_require__) {

"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony import */ var test__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! test */ "./src/lib/test/index.js");

exports.handler = async event => {
  console.log(JSON.stringify(event)); // const { userId } = event;

};

/***/ })

When the file contains an import, the function containing exports.handler is wrapped in parenthesis. Perhaps this is causing Lambda to not see handler somehow. This was the only difference I could find between the generated files.

  • Serverless-Webpack Version you’re using: 5.3.0
  • Webpack version you’re using: ^4.30.0
  • Serverless Framework Version you’re using: 1.4.3
  • Operating System: MacOS 10.14.5
  • Stack Trace (if available):

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
HyperBraincommented, Jun 7, 2019

Released as 5.3.1

2reactions
Hugoocommented, Jun 2, 2019

@HyperBrain , sure, I uploaded a simple repo here :

https://github.com/Hugoo/sls-webpack-bug

I didn’t try it on AWS but by using sls offline I can see the error.

Please let me know if you want more details.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS Lambda Python: 'handler' missing on module
In the case of the above error message, I attempted to call the handler method of index.js , but the corresponding method could...
Read more >
AWS Lambda errorMessage: Handler 'handler' missing on ...
The Python formatting seems to have gotten lost on the email, but your handler code doesn't seem to have anything inside it.
Read more >
pcntl_signal - Manual - PHP
The pcntl_signal() function installs a new signal handler or replaces the current signal handler for the signal indicated by signal .
Read more >
Firebase Apple SDK Release Notes - Google
Added missing app.google (1p domain) support in FDL SDK. ... Completion handler for fetchAndActivateWithCompletionHandler is now run on the main thread ...
Read more >
Distributing Jupyter Extensions as Python Packages
bundler extension: an importable Python module with generated File -> Download as ... RequestHandler Handler that serviced the bundle request model : dict ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found