rollup-plugin-node-globals

raw JSON →
1.4.0 verified Mon Apr 27 auth: no javascript deprecated

A Rollup plugin (v1.4.0, last released in 2018) that injects Node.js global polyfills—process, global, Buffer, __dirname, __filename—into bundled code, mimicking browserify's global shimming. It optimizes process.nextTick and process.browser to only pull in required parts, and resolves __dirname/__filename to the file on disk. Useful for migrating CommonJS or Node-centric code to ES module bundles, but superseded by @rollup/plugin-inject or manual polyfills; unmaintained and incompatible with Rollup v2+.

error Error: Cannot find module 'rollup-plugin-node-globals'
cause Package not installed or not in node_modules.
fix
Run npm install rollup-plugin-node-globals --save-dev.
error Error: 'plugin' is not defined
cause Invalid import syntax (e.g., using require in an ESM config).
fix
Use import globals from 'rollup-plugin-node-globals' in an ESM context.
error Error: Unexpected token: name (globals)
cause Rollup plugin configuration object missing parentheses when calling globals as a function.
fix
Call globals() instead of just globals in the plugins array.
deprecated Package is unmaintained and deprecated. Use @rollup/plugin-inject or manual polyfills instead.
fix Replace with @rollup/plugin-inject and configure polyfills manually.
gotcha The plugin may not work with Rollup v2 or higher due to plugin API changes.
fix Use @rollup/plugin-inject or fork/update the plugin.
gotcha __dirname and __filename are resolved to absolute paths on disk, not relative to the output bundle.
fix Manually replace with dynamic paths if needed.
gotcha The plugin does not polyfill all Node.js globals (e.g., setImmediate, clearImmediate) unless they are used in a global context.
fix Add individual polyfills for missing globals.
npm install rollup-plugin-node-globals
yarn add rollup-plugin-node-globals
pnpm add rollup-plugin-node-globals

Basic Rollup configuration using rollup-plugin-node-globals to polyfill process, global, Buffer, __dirname, and __filename.

import globals from 'rollup-plugin-node-globals';

export default {
  input: 'src/index.js',
  output: { file: 'dist/bundle.js', format: 'iife' },
  plugins: [
    globals({
      process: true,
      global: true,
      buffer: true,
      dirname: true,
      filename: true,
      baseDir: process.cwd()
    })
  ]
};