Serverless Rollup Plugin

raw JSON →
5.1.5 verified Mon Apr 27 auth: no javascript

A plugin for the Serverless Framework that bundles AWS Lambda functions using Rollup. Version 5.1.5 requires Node.js ≥18 and supports Serverless Framework v1–4 and Rollup v2–4. It automatically wraps handlers with module installation and file copying, supports concurrent builds, custom rollup configs, and ESM or CJS output. Differentiators: dependency injection per function, source map support, and Yarn/npm integration. Releases are automated via semantic-release on GitHub.

error Error: ENOENT: no such file or directory, open '/path/to/rollup.config.js'
cause The plugin cannot find the Rollup config file. Default path is rollup.config.js in the project root.
fix
Create a rollup.config.js file or specify the path using custom.rollup.config in serverless.yml.
error Error: Cannot find module 'rollup'
cause Rollup is not installed as a devDependency or is not in node_modules.
fix
Install rollup: npm install --save-dev rollup
error Error: The Serverless Framework plugin "serverless-rollup-plugin" is not recognized
cause The plugin is not listed in plugins section, or it's misspelled.
fix
Add 'serverless-rollup-plugin' to the plugins array in serverless.yml.
error Error: Requested concurrency 5 but only 1 available? (paraphrase) - Out of memory during concurrent builds
cause Too many concurrent rollup processes for available memory.
fix
Reduce custom.rollup.concurrency to a lower number (e.g., 2 or 3).
breaking The plugin requires Node.js >=18 starting from version 5.0.0.
fix Upgrade Node.js to 18+ or use an older version of the plugin (e.g., 4.x).
breaking Peer dependency on Serverless Framework dropped support for v1.x in version 4.0.0? (Verify version boundary)
fix Use Serverless >=2.0.0 or use plugin version 3.x.
deprecated The 'installCommand' option is deprecated; use 'npm install' or 'yarn add' directly in custom.rollup.dependencies? Not deprecated. Actually note: custom.rollup.installCommand still works but is not recommended because it does not handle lockfiles.
fix Instead of installCommand, manage dependencies with serverless's built-in package mechanism or use npm workspaces.
gotcha If output format is 'esm', the .mjs extension is used, but Lambda native ESM support requires Node.js 14+ and function configuration may need adjustments.
fix Ensure Lambda runtime is Node.js 14 or higher and that your handler path ends with .mjs in serverless.yml.
gotcha The plugin does not support Rollup plugins that need to run after the bundle is written (e.g., writeBundle hooks) because it uses rollup.generate() instead of rollup.write().
fix Use rollup.write() via custom script or use a different bundling approach for such plugins.
npm install serverless-rollup-plugin
yarn add serverless-rollup-plugin
pnpm add serverless-rollup-plugin

Minimal setup with serverless.yml and rollup.config.js for a Lambda function.

// Pre-requisites: Node.js >=18, serverless >=3.2, rollup installed
// 1. Install the plugin
// npm install --save-dev serverless-rollup-plugin

// 2. serverless.yml
plugins:
  - serverless-rollup-plugin

custom:
  rollup:
    config: rollup.config.js
    concurrency: 5

functions:
  hello:
    handler: src/hello.handler
    dependencies:
      - source-map-support

// 3. rollup.config.js (ESM)
export default {
  input: 'src/hello.js',
  output: {
    format: 'cjs',
    sourcemap: true,
    banner: "require('source-map-support').install();"
  }
};

// 4. Deploy
// npx serverless deploy

// The plugin will bundle src/hello.js, install source-map-support, and deploy to AWS Lambda.