Registry / devops / esbuild-plugin-cdn-imports

esbuild-plugin-cdn-imports

JSON →
library2.0.0jsnpmunverified

An esbuild plugin (v2.0.0) that intercepts import statements and resolves them to CDN URLs (esm.sh, unpkg, jsdelivr, skypack), enabling browser-side module resolution without a filesystem. Requires esbuild >=0.20.0 and Node >=18. Ships TypeScript types. Key differentiator: supports multiple CDNs and per-package version pinning, but some dependencies may not work from a CDN.

npm install esbuild-plugin-cdn-imports
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-CDN
E
esbuild-plugin-cdn-imports
devopsjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

CDNImports
import { CDNImports } from 'esbuild-plugin-cdn-imports'
import CDNImports from 'esbuild-plugin-cdn-imports'
Named export only; no default export.
CDNImports
import { CDNImports } from 'esbuild-plugin-cdn-imports'
const { CDNImports } = require('esbuild-plugin-cdn-imports')
ESM-only package; CJS require not supported.
CDNImportsOptions
import type { CDNImportsOptions } from 'esbuild-plugin-cdn-imports'
TypeScript users should import the type for options validation.

Configures esbuild to replace imports of 'react' and 'react-dom' with esm.sh CDN URLs, excluding '@prisma/client' from transformation.

import { build } from 'esbuild'; import { CDNImports } from 'esbuild-plugin-cdn-imports'; await build({ entryPoints: ['./src/index.js'], bundle: true, outfile: './dist/bundle.js', format: 'esm', platform: 'browser', plugins: [ CDNImports({ cdn: 'esm', versions: { 'react': '17.0.2', 'react-dom': '17.0.2' }, exclude: ['@prisma/client'] }) ] });
Debug
Known issues
breakingNode.js >=18 required; plugin uses modern APIs (e.g., node:module) not available in older versions.
fix
Upgrade Node.js to version 18 or later.
affects: <18
breakingesbuild >=0.20.0 required as peer dependency.
fix
Update esbuild to version 0.20.0 or later.
affects: >=2.0.0
deprecatedSupport for esbuild <0.19.0 dropped in v1.2.0; earlier versions may use an older plugin version.
fix
Upgrade esbuild to at least 0.19.0.
affects: >=1.2.0
gotchaSome npm packages (e.g., those with native modules or certain Node.js APIs) may not work when imported from a CDN.
fix
Use the 'exclude' option to bypass CDN resolution for incompatible packages, or verify CDN compatibility beforehand.
affects: >=0.0.0
breakingESM-only package; cannot be imported with CommonJS require().
fix
Use import syntax instead of require(), or set your project's type to module.
affects: >=0.0.0
deprecatedThe 'skypack' CDN may be less reliable; esm.sh and jsdelivr are recommended.
fix
Prefer 'esm' or 'jsdelivr' CDN options.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'esbuild-plugin-cdn-imports'
Package not installed correctly or missing peer dependency.
fix
Run 'npm install -D esbuild esbuild-plugin-cdn-imports'.
TypeError: CDNImports is not a function
Import might be using default import instead of named import.
fix
Use 'import { CDNImports } from 'esbuild-plugin-cdn-imports''.
Error: [plugin: cdn-imports] Unsupported CDN 'xyz'
Provided CDN name is not in the supported list.
fix
Use one of: 'esm', 'unpkg', 'jsdelivr', 'skypack'.
Build failed with 1 error: error: require() of ES Module not supported
The project is using CommonJS require() to import an ESM-only plugin.
fix
Switch to ES module imports or set 'type': 'module' in package.json.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
esbuildrequiredPeer dependency required for plugin usage
Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-plugin-cdn-imports — npm install esbuild-plugin-cdn-imports · libregistry