Registry / devops / rollup-plugin-shim

rollup-plugin-shim

JSON →
library1.0.0jsnpmunverified

A Rollup plugin that replaces module imports with a specified string shim, useful for stripping out dev-time dependencies like 'debug' in production builds. Stable at v1.0.0 since 2017, with minimal releases. Unlike rollup-plugin-alias, this plugin replaces the module content inline with a string rather than pointing to another file, making it ideal for small shims. Best for simple noop replacements; for complex aliasing, use rollup-plugin-alias instead. Active maintenance is low, but the plugin works with Rollup 0.x and 1.x.

npm install rollup-plugin-shim
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-SHIM
R
rollup-plugin-shim
devopsjavascriptv1.0.0
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

default (shim)
import shim from 'rollup-plugin-shim'
import { shim } from 'rollup-plugin-shim'
The package exports a single default function; named import will result in undefined.
shim (CommonJS)
const shim = require('rollup-plugin-shim')
CommonJS require works, but Rollup configs typically use ESM import.
shim (TypeScript)
import shim = require('rollup-plugin-shim')
import shim from 'rollup-plugin-shim' // not typed, use require for TS compatibility
Package has no TypeScript definitions; use require style or add a module declaration.

Shows how to configure the plugin to replace 'debug' and 'fs' imports with noop stubs in a Rollup config.

import shim from 'rollup-plugin-shim'; export default { input: 'src/main.js', output: { format: 'es' }, plugins: [ shim({ 'debug': `export default () => () => undefined`, 'fs': `export function writeFileSync() {}` }) ] };
Debug
Known issues
gotchaPlugin overwrites imports globally; if two modules use the same import name but expect different behavior, shimming may break one of them.
fix
Use distinct keys or handle per-module with custom resolve.
affects: >=1.0.0
gotchaShim values are strings that are evaluated as modules; syntax errors in the shim string will cause build failures.
fix
Ensure shim strings are valid JavaScript/ES module syntax.
affects: >=1.0.0
gotchaThe plugin may not work with Rollup >=2.0.0 due to API changes; it was developed for Rollup 0.x/1.x.
fix
Test with your Rollup version; consider using '@rollup/plugin-alias' or newer alternatives.
affects: >=1.0.0
gotchaKeys in the shim object must match the import specifier exactly, including file extensions if used in the import.
fix
Use full paths or bare specifiers as they appear in import statements.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Unexpected token (Note that you need plugins to import files that are not JavaScript)
Shim string contains syntax errors or invalid module format.
fix
Correct the shim string to be valid ES module syntax.
TypeError: shim is not a function
Importing the plugin incorrectly (e.g., using named import when default is needed).
fix
Use default import: `import shim from 'rollup-plugin-shim'`.
Error: Cannot find module 'rollup-plugin-shim'
Package not installed or not in node_modules.
fix
Run `npm install rollup-plugin-shim --save-dev` or `yarn add -D rollup-plugin-shim`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
rolluprequiredRequires Rollup as a peer dependency to function as a plugin.
Agent activity
6 hits · last 30 days
node
6
Resources
rollup-plugin-shim — npm install rollup-plugin-shim · libregistry