rollup-plugin-bower-resolve
raw JSON → 3.1.0 verified Mon Apr 27 auth: no javascript maintenance
A Rollup plugin that resolves module imports using the Bower resolution algorithm, allowing Rollup to bundle Bower components. Version 3.1.0 is the latest stable release, supporting Rollup v1 through v4 and Node >=14. Unlike npm-centric plugins, this plugin is specifically designed for projects that still rely on Bower for dependency management. It offers options for offline mode, custom working directories, and overrides for main entry points. The plugin is in maintenance mode as the Bower ecosystem has largely been superseded by npm/Yarn.
Common errors
error Error: Cannot find module 'rollup-plugin-bower-resolve' ↓
cause Package is ESM-only starting from v3.0.0; using require() in a CommonJS context fails.
fix
Switch to import syntax: import bowerResolve from 'rollup-plugin-bower-resolve'
error TypeError: bowerResolve is not a function ↓
cause Using require() in Node.js without .default access.
fix
Use const bowerResolve = require('rollup-plugin-bower-resolve').default;
Warnings
breaking Version 3.0.0 dropped support for Node <14.0.0 and switched to ESM-only exports. ↓
fix Update Node to >=14.0.0 and use import syntax instead of require.
deprecated The 'jsnext' option is deprecated; use 'module' instead. ↓
fix Set module: true and jsnext: false to future-proof.
gotcha The 'offline' option defaults to true, which may cause build failures if Bower cache is not populated. ↓
fix Set offline: false to fetch from remote, or ensure bower install has been run.
breaking Version 2.0.0 requires Rollup 2.x.x and Node >=10.0.0; Rollup 1.x no longer supported. ↓
fix Upgrade Rollup to >=2.0.0 and Node to >=10.0.0.
breaking Version 1.0.0 removed support for Rollup versions below 1.0.0 and Node <6.0.0. ↓
fix Upgrade Rollup to >=1.0.0 and Node to >=6.0.0.
Install
npm install rollup-plugin-bower-resolve yarn add rollup-plugin-bower-resolve pnpm add rollup-plugin-bower-resolve Imports
- default wrong
const bowerResolve = require('rollup-plugin-bower-resolve')correctimport bowerResolve from 'rollup-plugin-bower-resolve' - bowerResolve wrong
const bowerResolve = require('rollup-plugin-bower-resolve')correctconst bowerResolve = require('rollup-plugin-bower-resolve').default - Plugin
import type { Plugin } from 'rollup'; import bowerResolve from 'rollup-plugin-bower-resolve';
Quickstart
import { rollup } from 'rollup';
import bowerResolve from 'rollup-plugin-bower-resolve';
import commonjs from '@rollup/plugin-commonjs';
const bundle = await rollup({
input: 'src/index.js',
plugins: [
bowerResolve({
cwd: process.cwd(),
offline: true,
module: true,
jsnext: true,
skip: ['some-big-dependency']
}),
commonjs()
]
});
await bundle.write({
file: 'dist/bundle.js',
format: 'iife',
name: 'MyBundle'
});
console.log('Bundle created successfully.');