Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Issue with working serverless-webpack

Open
#266 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, webpack
Domain
cloud

Research direction

Start with the serverless.yaml handler configuration and webpack.config.js, then compare the generated .webpack paths with the _HANDLER value shown in the error. Check how the plugin and serverless-webpack derive the packaged handler path. Done means the deployed handler path matches the generated .webpack/a-dir/a-handler.handle location and the LocalStack invocation starts successfully.

Written by the indexing model from the issue text.

Description

serverless-webpack status: backlog status: response required

As the documentation says, I added this configuration inside my custom property in the serverless.yaml

  localstack:
    stages:
      # list of stages for which the plugin should be enabled
      - local
      - development
    host: http://localhost  # optional - LocalStack host to connect to
    edgePort: 4566  # optional - LocalStack edge port to connect to
    autostart: true  # optional - Start LocalStack in Docker on Serverless deploy
    networks: #optional - attaches the list of networks to the localstack docker container after startup
      - host
      - overlay
    lambda:
      # Enable this flag to improve performance
      mountCode: true  # specify either "true", or a relative path to the root Lambda mount path

The webpack config is this for the serverless:

 webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true
    excludeFiles: tests/**/*.{js,ts}
    keepOutputDirectory: true

This is the webpack configuration:

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

module.exports = {
  entry: slsw.lib.entries,
  target: 'node',
  mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
  optimization: {
    minimize: false,
  },
  plugins: [],
  performance: {
    // Turn off size warnings for entry points
    hints: false,
  },
  externals: [nodeExternals()],
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: 'ts-loader?configFile=tsconfig.build.json',
        exclude: [/node_modules/, /tests/],
      },
    ],
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
  output: {
    libraryTarget: 'commonjs2',
    path: path.join(__dirname, '.webpack'),
    filename: '[name].js',
  },
  cache: {
    type: 'filesystem',
  },
};

And I'm getting this error:

Execution environment startup failed: {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'a-handler'\nRequire stack:\n- /var/runtime/index.mjs","trace":["Runtime.ImportModuleError: Error: Cannot find module 'a-handler'","Require stack:","- /var/runtime/index.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:1087:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)","    at async start (file:///var/runtime/index.mjs:1282:23)","    at async file:///var/runtime/index.mjs:1288:1"]}

And it looks like is because the handler path is incorrect, it says this

'_HANDLER': '.webpack/service/src/a-dir/a-handler.handle'

But when webpack package the code is located in .webpack/a-dir/a-handler.handle, what would be the solution for that, I'm kind of lost, should I update the output path?

Dominant language
JavaScript
Stars
542
Forks
92
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from localstack/serverless-localstack

All issues in localstack/serverless-localstack

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.