rollup-plugin-sourcemaps
raw JSON → 0.6.3 verified Mon Apr 27 auth: no javascript
Rollup plugin that loads existing source maps from sourceMappingURL comments in JavaScript files. Version 0.6.3 is the latest stable, with infrequent releases. It works with Rollup >=0.31.2 and helps preserve source maps from transpiled files or external modules before final bundling. Unlike Babel's inputSourceMap option, this plugin works with any source map source, making it useful when consuming pre-compiled dependencies or when using multiple transpilation steps.
Common errors
error Error: Cannot find module 'rollup-plugin-sourcemaps' ↓
cause Package not installed
fix
npm install --save-dev rollup-plugin-sourcemaps
error TypeError: sourcemaps is not a function ↓
cause Wrong import style (e.g., using named import instead of default)
fix
Use 'import sourcemaps from "rollup-plugin-sourcemaps"' and call sourcemaps()
error Error: You must specify output.sourcemap: true to use this plugin ↓
cause Output sourcemap option not set
fix
Add sourcemap: true to Rollup output config
error Error: Could not resolve source map for '...' ↓
cause Missing source map file or wrong path in sourceMappingURL
fix
Ensure the referenced .map file exists or fix the path
Warnings
breaking Rollup 3 dropped support for some plugin hooks; ensure compatibility with this plugin version ↓
fix Update to latest rollup-plugin-sourcemaps and Rollup 3
gotcha Plugin only works with files that have a sourceMappingURL comment; inline source maps are not supported ↓
fix Ensure your input files have external source map references (e.g., //# sourceMappingURL=file.js.map)
gotcha Output must have sourcemap:true for the plugin to take effect ↓
fix Add sourcemap: true to output options in rollup.config.js
deprecated This plugin is in maintenance mode; consider using Rollup's built-in source map handling or plugin hooks ↓
fix Migrate to Rollup's native source map support or use @rollup/plugin-sourcemaps if available
Install
npm install rollup-plugin-sourcemaps yarn add rollup-plugin-sourcemaps pnpm add rollup-plugin-sourcemaps Imports
- sourcemaps wrong
const sourcemaps = require('rollup-plugin-sourcemaps')correctimport sourcemaps from 'rollup-plugin-sourcemaps'
Quickstart
import sourcemaps from 'rollup-plugin-sourcemaps';
import { rollup } from 'rollup';
const bundle = await rollup({
input: 'src/index.js',
plugins: [sourcemaps()],
output: {
sourcemap: true,
file: 'dist/bundle.js',
format: 'esm'
}
});
await bundle.write({
sourcemap: true,
file: 'dist/bundle.js',
format: 'esm'
});