vite-plugin-node-externals
raw JSON → 0.0.1 verified Mon Apr 27 auth: no javascript deprecated
Vite plugin that wraps rollup-plugin-node-externals to automatically externalize Node.js built-in modules and npm dependencies in Vite builds. Version 0.0.1, released in 2021. No active release cadence. The main differentiator is that it fixes Vite's plugin ordering issue by enforcing 'pre' type, allowing rollup-plugin-node-externals to work correctly. However, the author recommends against using it and suggests directly configuring rollup-plugin-node-externals with enforce: 'pre' instead.
Common errors
error Error: Must use import to load ES Module: /path/to/vite-plugin-node-externals/index.mjs ↓
cause Package is ESM-only, but project uses CommonJS require()
fix
Change require() to import() or switch to dynamic import.
error TypeError: nodeExternals is not a function ↓
cause Importing named export 'nodeExternals' from default export
fix
Use import nodeExternals from 'vite-plugin-node-externals' (default) or import { nodeExternals } from '...' (named).
error Error: The plugin 'vite-plugin-node-externals' is not compatible with current Vite version ↓
cause Vite version mismatch; package may not support Vite 3+
fix
Use rollup-plugin-node-externals directly or update vite-plugin-node-externals if available.
Warnings
deprecated Author recommends not using this package; use rollup-plugin-node-externals directly with enforce: 'pre'. ↓
fix Replace with rollup-plugin-node-externals and set enforce: 'pre'.
breaking Does not support CommonJS require() – only ES module imports work. ↓
fix Use import syntax or switch to a CJS-compatible wrapper.
gotcha Options passed to nodeExternals() may not be fully forwarded to rollup-plugin-node-externals due to thin wrapper. ↓
fix Use rollup-plugin-node-externals directly for full option support.
Install
npm install vite-plugin-node-externals yarn add vite-plugin-node-externals pnpm add vite-plugin-node-externals Imports
- default wrong
const nodeExternals = require('vite-plugin-node-externals')correctimport nodeExternals from 'vite-plugin-node-externals' - nodeExternals wrong
import nodeExternals from 'vite-plugin-node-externals'correctimport { nodeExternals } from 'vite-plugin-node-externals' - PluginOptions wrong
import { PluginOptions } from 'vite-plugin-node-externals'correctimport type { PluginOptions } from 'vite-plugin-node-externals'
Quickstart
// vite.config.js
import { defineConfig } from 'vite';
import nodeExternals from 'vite-plugin-node-externals';
export default defineConfig({
plugins: [
nodeExternals(),
],
});