{"id":22814,"library":"vite-plugin-resolve-externals","title":"Vite Plugin Resolve Externals","description":"A Vite plugin (v0.2.2) that resolves external dependencies by mapping import specifiers to global variables or custom code snippets. It allows configuring external mappings via plugin options or Vite's resolve.externals configuration. Useful for replacing Node.js or client-side libraries with CDN scripts in Vite projects. It supports both simple global mappings and advanced code generation for scoped exports. No recent updates; stable but minimal feature set compared to alternatives like rollup-plugin-external-globals. Suitable for small to medium projects needing quick externals resolution.","status":"active","version":"0.2.2","language":"javascript","source_language":"en","source_url":"https://github.com/lceric/vite-plugin-resolve-externals","tags":["javascript","vite","plugin","resolve","externals"],"install":[{"cmd":"npm install vite-plugin-resolve-externals","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-resolve-externals","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-resolve-externals","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin runs within Vite's build pipeline","package":"vite","optional":false}],"imports":[{"note":"The package is ESM-only. Use import syntax for Vite config.","wrong":"const resolveExternalsPlugin = require('vite-plugin-resolve-externals')","symbol":"default","correct":"import resolveExternalsPlugin from 'vite-plugin-resolve-externals'"},{"note":"The package exports a single default function; no named export exists.","wrong":"import { resolveExternalsPlugin } from 'vite-plugin-resolve-externals'","symbol":"resolveExternalsPlugin (default)","correct":"import * as plugin from 'vite-plugin-resolve-externals'"},{"note":"CommonJS require() will fail in ESM context. Use dynamic import() with .default.","wrong":"const resolveExternalsPlugin = require('vite-plugin-resolve-externals')","symbol":"resolveExternalsPlugin via CJS require()","correct":"const resolveExternalsPlugin = (await import('vite-plugin-resolve-externals')).default"}],"quickstart":{"code":"// vite.config.js\nimport { defineConfig } from 'vite';\nimport resolveExternalsPlugin from 'vite-plugin-resolve-externals';\n\nexport default defineConfig({\n  plugins: [\n    resolveExternalsPlugin({\n      vue: 'Vue',\n      'vue-router': 'VueRouter',\n      axios: 'axios',\n    }),\n  ],\n});","lang":"javascript","description":"Basic setup: map 'vue' to global 'Vue', 'vue-router' to 'VueRouter', 'axios' to 'axios' in Vite project."},"warnings":[{"fix":"Prefer passing externals as the first argument to resolveExternalsPlugin() instead of using resolve.externals in Vite config.","message":"The plugin overrides Vite's resolve.externals if both are set. Configure via plugin option only to avoid conflicts.","severity":"gotcha","affected_versions":">=0.2.2"},{"fix":"Wrap custom exports in a function that returns a template literal. Test by building with --debug flag.","message":"When using custom code strings for globals, ensure they are valid JavaScript. Syntax errors will cause silent build failures.","severity":"gotcha","affected_versions":">=0.2.2"},{"fix":"Move externals from resolve.externals to the plugin call: resolveExternalsPlugin({...})","message":"The 'resolve.externals' configuration in Vite's resolve option is deprecated; use the plugin's argument instead.","severity":"deprecated","affected_versions":">=0.2.0"},{"fix":"Pass externals as argument to resolveExternalsPlugin().","message":"Plugin no longer reads from 'resolve.externals' by default; must pass explicitly.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Ensure the global is available in the browser before the script runs, e.g., via CDN script tags.","message":"Named exports from custom code strings may not work if the global variable is not defined at build time.","severity":"gotcha","affected_versions":">=0.2.2"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install as devDependency: npm install -D vite-plugin-resolve-externals","cause":"Package not installed or used in TypeScript without type declarations.","error":"Error: Cannot find module 'vite-plugin-resolve-externals'"},{"fix":"Use 'import resolveExternalsPlugin from ...' or 'import * as pkg from ...; pkg.default(...)'","cause":"Using named import instead of default import.","error":"TypeError: resolveExternalsPlugin is not a function"},{"fix":"Replace require() with import or use dynamic import: const resolve = (await import(...)).default","cause":"Using require() in an ESM context (vite.config.js is ESM by default).","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Pass externals directly to resolveExternalsPlugin() as the first argument.","cause":"Plugin version prior to 0.2.0? Actually, version 0.2.0+ ignores resolve.externals.","error":"Error: The externals option in 'resolve' is not supported by this plugin anymore"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}