rollup-plugin-skypin

raw JSON →
1.1.2 verified Fri May 01 auth: no javascript

A Rollup plugin that converts bare Node-style imports into pinned URLs from skypack.dev CDN, enabling browser-friendly ESM imports from npm packages. Version 1.1.2 is stable and actively maintained. It supports options for minified vs. normal builds, pinned URLs for production, custom replacement logic, and handling of relative/web imports. Key differentiator: lightweight, focused alternative to other CDN plugin approaches; based on skypin library.

error Error: Cannot find module 'skypin'
cause Missing dependency skypin; it is a peer dependency but not automatically installed.
fix
npm install skypin --save-dev
error TypeError: (intermediate value) is not a function
cause Using default import instead of named import: import skypin from 'rollup-plugin-skypin' returns undefined.
fix
Use named import: import { skypin } from 'rollup-plugin-skypin'
error Error: Could not resolve import for 'some-package'
cause shouldReplace returned true for a package that is not on skypack (e.g., relative path or Node built-in).
fix
In shouldReplace, check if id is an npm package name and return false for local/built-in modules.
error Module 'rollup-plugin-skypin' resolved to a CommonJS file
cause Old Rollup configuration (format 'cjs') may not handle ESM plugin correctly.
fix
Ensure Rollup config uses format 'esm' or use rollup-plugin-skypin in a .mjs config file.
breaking Plugin expects Rollup v1+; may not work with older Rollup versions.
fix Ensure Rollup >= 1.0.0 is installed.
gotcha shouldReplace returning a string replaces the module id but does NOT handle the resolution; it overrides the original id.
fix Return false to keep original behavior, or a CDN-ready URL string to replace entirely.
gotcha relative_external option: when true, relative imports (./foo) are marked external; if false, they are processed by skypin (likely error).
fix Set relative_external: true if you have local files; false only if all imports are npm packages.
deprecated Option 'minified' default true may change in future versions.
fix Explicitly set minified: true to preserve current behavior.
gotcha Plugin does not handle Node.js built-in modules; they must be externalized separately.
fix Add builtins to rollup external config or use @rollup/plugin-node-resolve with preferBuiltins: false.
npm install rollup-plugin-skypin
yarn add rollup-plugin-skypin
pnpm add rollup-plugin-skypin

Showcases a Rollup configuration using the skypin plugin with options: minified, pinned URL, and custom replacement logic.

// rollup.config.js
import { skypin } from 'rollup-plugin-skypin';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'esm'
  },
  plugins: [
    skypin({
      minified: true,
      pinned: true,
      shouldReplace: (id) => id.startsWith('some-prefix') ? id : false
    })
  ]
};