serverless-heaven / serverless-webpack

Serverless plugin to bundle your lambdas with Webpack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When context is used in the webpack config, handlers arent found

jdbevan opened this issue · comments

This is a Bug Report

Description

For bug reports:

  • What went wrong?
    I had a context path defined in my webpack config. serverless-webpack therefore didn't find the relevant files for the handlers because it uses the serverless.config.servicePath

  • What did you expect should have happened?
    It should have found my files, or told me where it was looking for them

  • What was the config you used?

service: jons-service

provider:
  name: aws
  runtime: nodejs4.3
  memorySize: 128
  timeout: 60
  stage: dev
  region: us-west-2

plugins:
  - serverless-webpack

custom:
  webpack:
    packager: yarn
    includeModules:
      forceExclude:
        - aws-sdk

functions:
  my-function:
    handler: modules/foo-bar.doSomething

and

const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const slsw = require('serverless-webpack');

const entry = Object.keys(slsw.lib.entries).reduce((acc, path) => {
    return {
        ...acc,
        [path]: ['babel-polyfill'].concat(acc[path])
    }
}, slsw.lib.entries);

const config = {
    context: __dirname + "/app"
    target: "node",
    mode: 'production',
    entry,
    externals: ['aws-sdk'],
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: [{
                    loader: 'babel-loader',
                    options: {
                        presets: [["env", {
                            "targets": {
                                "node": "4.3"
                            }
                        }]]
                    }
                }]
            }
        ]
    },

    optimization: {
        minimizer: [
            new UglifyJsPlugin({
                parallel: true,
                uglifyOptions: {
                    mangle: false
                }
            })
        ]
    },

    plugins: [
        new webpack.NoEmitOnErrorsPlugin(),
        new webpack.DefinePlugin({
            'process.env.NODE_ENV': 'production'
        })
    ]
};

module.exports = config;
  • What stacktrace or error message from your provider did you see?
    No matching handler found for 'modules/foo-bar'. Check your service definition.

For feature proposals:

  • What is the use case that should be solved. The more detail you describe this in the easier it is to understand for us.
  • If there is additional config how would it look

Similar or dependent issue(s):
*

Additional Data

  • Serverless-Webpack Version you're using: 5.1.5
  • Webpack version you're using: 4.12.1
  • Serverless Framework Version you're using: 1.27.3
  • Operating System: macOS Sierra 10.12.6
  • Stack Trace (if available):

Hi @jdbevan , good catch 👍