Registry / devops / serverless-webpack

serverless-webpack

JSON →
library5.15.4jsnpmunverified

A Serverless Framework plugin that bundles Lambda function code using Webpack, enabling tree-shaking, individual packaging, Babel transpilation, and custom loaders. Current stable version is 5.15.4, released April 2025. Requires Node.js >= 20 and supports Serverless v1 through v4 (with esbuild disabled in v4). Active development with monthly releases. Compared to serverless-bundle or serverless-esbuild, this plugin offers broader Webpack version support (3, 4, 5), NPM/Yarn packaging, async webpack config, and seamless integration with serverless-offline.

npm install serverless-webpack
INSTALL
IMPORT
SIG · SERVERLESS-WEBPACK
S
serverless-webpack
devopsjavascriptv5.15.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
plugins: - serverless-webpack
plugins: - serverless-webpack-plugin
Plugins in serverless.yml use the package name directly, no import statement.
slsw
const slsw = require('serverless-webpack')
import slsw from 'serverless-webpack'
The module exports a single function via module.exports, not ESM. Use require() in webpack.config.js.
lib
slsw.lib
slsw.default.lib
slsw.lib provides access to serverless instance and other utilities. No default export.
ServerlessWebpack (TypeScript)
import ServerlessWebpack from 'serverless-webpack';
const ServerlessWebpack = require('serverless-webpack').default;
TypeScript typings allow default import, but the CJS runtime still works. Prefer import syntax for type safety.

Initialize a Serverless service with serverless-webpack, install plugin, configure webpack for Node.js target, and create a basic handler.

npm install serverless-webpack --save-dev # serverless.yml service: my-service plugins: - serverless-webpack provider: name: aws runtime: nodejs20.x custom: webpack: webpackConfig: 'webpack.config.js' includeModules: false functions: hello: handler: handler.hello // webpack.config.js const path = require('path'); module.exports = { entry: './handler.js', target: 'node', output: { libraryTarget: 'commonjs2', path: path.join(__dirname, '.webpack'), filename: '[name].js', }, }; // handler.js exports.hello = async (event) => { return { statusCode: 200, body: 'Hello from serverless-webpack!' }; };
Debug
Known issues
breakingNode.js >= 20 required as of v5.15.4. Node 18 dropped in v5.15.4, Node 16 dropped in v5.14.0.
fix
Upgrade Node.js to version 20 or later.
affects: >=5.14.0
breakingServerless v4 requires disabling built-in esbuild: set build.esbuild: false in serverless.yml.
fix
Add build:
  esbuild: false to serverless.yml.
affects: >=5.15.0
breakingRemoved is-builtin-module dependency in v5.15.4. Might break if relying on that polyfill.
fix
Ensure your code does not depend on is-builtin-module being available.
affects: >=5.15.4
deprecatedServerless v1-v3 support may be dropped in future releases. The peer dependency allows v4.
fix
Migrate to Serverless v4 if needed.
affects: >=5.15.0
gotchaNative ESM output requires copyPackageSectionNames config and may need package.json adjustments.
fix
Use copyPackageSectionNames in custom.webpack and ensure package.json has required fields.
affects: >=5.12.0
gotchaE2E tests and some features may fail on Windows due to spawn EINVAL on Node > 20.12.2 (fixed in v5.14.0).
fix
Upgrade to v5.14.0+ or use Node <= 20.12.2 on Windows.
affects: >=5.0.0 <5.14.0
gotchaWhen using serverless-offline, webpack config must not have mode: 'production' to allow source maps.
fix
Use mode: 'development' or set devtool appropriately for local runs.
affects: >=4.0.0
Errors
Common errors & fixes
Error: Cannot find module 'serverless-webpack'
Plugin not installed or not in devDependencies.
fix
Run npm install serverless-webpack --save-dev.
Configuration error: Cannot resolve 'webpack'
Missing webpack as a devDependency.
fix
Run npm install webpack --save-dev.
TypeError: slsw.lib.serverless.providers.aws.getAccountId is not a function
Using async webpack config outside of Lambda edge context.
fix
Ensure you are using the correct slsw object from the plugin; check serverless version compatibility.
Error: spawn EINVAL
Node > 20.12.2 on Windows, older serverless-webpack version.
fix
Upgrade serverless-webpack to v5.14.0+.
Upgrade
Version history
5.15.4latest on npm
Audit
Dependencies
serverlessrequiredpeer dependency - plugin hooks into Serverless lifecycle
webpackrequiredpeer dependency - core bundler
ts-nodeoptionaloptional peer dependency for TypeScript config support
Agent activity
8 hits · last 30 days
node
8
Resources