rollup-plugin-http-resolve
raw JSON → 4.0.1-alpha.0 verified Sat Apr 25 auth: no javascript
A Rollup plugin that resolves imports via HTTP(S) URLs, enabling bundling of code from CDNs like esm.sh or unpkg. Current version 4.0.1-alpha.0 has irregular release cadence (last release ~2022). Key differentiator: it allows Rollup to fetch and bundle dependencies directly from HTTP sources, with optional caching and fallback to CDN resolution. Requires Node.js 14+. Written in TypeScript with built-in types.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module not supported. ↓
cause Using CommonJS require() to load an ESM-only package.
fix
Use dynamic import: const { httpResolve } = await import('rollup-plugin-http-resolve');
error TypeError: httpResolve is not a function or does not provide a plugin. ↓
cause Incorrect import (default import instead of named import) or mismatched Rollup version.
fix
Use named import: import { httpResolve } from 'rollup-plugin-http-resolve';
Warnings
breaking Requires Rollup >=2.0; compatibility with Rollup 3.x is untested. ↓
fix Ensure Rollup version is >=2.0 and <4.0.0, or test with Rollup 3.x.
deprecated Version 4.0.1-alpha.0 is an alpha release and may have unstable APIs. ↓
fix Use 3.x stable versions if available, or pin to known working alpha.
gotcha ESM-only package; CommonJS require throws error. ↓
fix Use dynamic import() or convert project to ESM.
gotcha HTTP imports are not cached by default; may cause repeated network requests. ↓
fix Provide a cache Map in options to avoid redundant fetches.
Install
npm install rollup-plugin-http-resolve yarn add rollup-plugin-http-resolve pnpm add rollup-plugin-http-resolve Imports
- httpResolve wrong
const httpResolve = require('rollup-plugin-http-resolve')correctimport { httpResolve } from 'rollup-plugin-http-resolve' - HttpResolveOptions wrong
import { HttpResolveOptions } from 'rollup-plugin-http-resolve'correctimport type { HttpResolveOptions } from 'rollup-plugin-http-resolve'
Quickstart
import { httpResolve } from 'rollup-plugin-http-resolve';
import { rollup } from 'rollup';
async function bundle() {
const bundle = await rollup({
input: 'https://example.com/module.js',
plugins: [
httpResolve({
cache: new Map(),
fallback(id) {
if (!id.startsWith('.')) {
return `https://esm.sh/${id}`;
}
}
})
]
});
const { output } = await bundle.generate({ format: 'es' });
console.log(output[0].code);
}
bundle();