{"id":22608,"library":"vite-plugin-cdn2","title":"vite-plugin-cdn2","description":"A Vite plugin that replaces imported modules with CDN-hosted scripts and links during build. Current stable version is 1.1.0 (released 2024). Lightweight alternative to vite-plugin-cdn-import with TypeScript types, supports custom CDN resolvers, and works with Vue/JSX/TS. Actively maintained with frequent patch releases.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/nonzzz/vite-plugin-cdn","tags":["javascript","vite","vite-plugin","cdn","vite-plugin-cdn","typescript"],"install":[{"cmd":"npm install vite-plugin-cdn2","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-cdn2","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-cdn2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This is a Vite plugin; requires Vite as a peer dependency.","package":"vite","optional":false}],"imports":[{"note":"ESM-only; CommonJS require will fail.","wrong":"const cdn = require('vite-plugin-cdn2')","symbol":"cdn","correct":"import { cdn } from 'vite-plugin-cdn2'"},{"note":"No default export; only named export 'cdn'.","wrong":"import cdn from 'vite-plugin-cdn2'","symbol":"default","correct":"import { cdn } from 'vite-plugin-cdn2'"},{"note":"IModule is a type; use 'import type' to avoid runtime inclusion.","wrong":"import { IModule } from 'vite-plugin-cdn2'","symbol":"type IModule","correct":"import type { IModule } from 'vite-plugin-cdn2'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport { cdn } from 'vite-plugin-cdn2';\n\nexport default defineConfig({\n  plugins: [\n    cdn({\n      modules: [\n        { name: 'vue', var: 'Vue', path: 'https://unpkg.com/vue@3/dist/vue.global.prod.js' },\n        'react'\n      ]\n    })\n  ]\n});","lang":"typescript","description":"Shows how to replace Vue and React modules with CDN links in Vite config."},"warnings":[{"fix":"Use 'vite-plugin-cdn2' package and update imports.","message":"Plugin renamed from 'vite-plugin-cdn' to 'vite-plugin-cdn2'. Old package is deprecated.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Set 'apply: 'serve'' to use during development if needed.","message":"Plugin only applies during build by default (apply: 'build'). Does not work in dev mode.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use the 'cdn' plugin with 'modules' option instead.","message":"The 'external' plugin option exposed in v0.13.0 is deprecated in v1.0.0+ and will be removed.","severity":"deprecated","affected_versions":">=1.0.0 <2.0.0"},{"fix":"Upgrade to >=0.13.0 which includes fix for monorepo.","message":"Module resolution fails in monorepo setups if the module's package.json is not hoisted.","severity":"gotcha","affected_versions":"<0.13.0"},{"fix":"Switch project to ESM or use dynamic import().","message":"Starting from v1.0.0, the plugin is ESM-only. CJS projects cannot import it.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'npm install vite-plugin-cdn2 -D' and import correctly.","cause":"Package not installed or typo (missing '2').","error":"Error: Cannot find module 'vite-plugin-cdn2'"},{"fix":"Use 'import { cdn } from 'vite-plugin-cdn2''.","cause":"Default import used instead of named import.","error":"TypeError: cdn is not a function"},{"fix":"Change import to named: 'import { cdn } from ...'.","cause":"Default import used when only named export exists.","error":"Uncaught SyntaxError: The requested module 'vite-plugin-cdn2' does not provide an export named 'default'"},{"fix":"Ensure plugin is placed before built-in plugins and 'apply' is set correctly.","cause":"Plugin applied incorrectly (likely missing 'apply' or placed after Vite built-in plugins).","error":"Error: [vite] Internal server error: Cannot read properties of undefined (reading 'transform')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}