rollup-plugin-node-resolve

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

Rollup plugin that resolves third-party modules from node_modules using the Node resolution algorithm. Version 2.0.6 is stable but superseded by @rollup/plugin-node-resolve. It allows bundling external npm packages with Rollup by resolving entry points via package.json fields (main, jsnext:main, browser). Key differentiator: enables Rollup to bundle CommonJS modules when combined with rollup-plugin-commonjs. Not ES module aware: it resolves based on legacy fields. Has known footguns with browser field and preferBuiltins.

error Error: Cannot find module 'rollup-plugin-node-resolve'
cause Missing npm install or wrong package name after migration.
fix
npm install rollup-plugin-node-resolve --save-dev or migrate to @rollup/plugin-node-resolve
error TypeError: (0 , _nodeResolve.default) is not a function
cause Named import instead of default import from the plugin.
fix
Use default import: import nodeResolve from 'rollup-plugin-node-resolve'
error The 'browser' option should be an alias for 'mainFields: ["browser", "module", "main"]'
cause In newer versions, browser option is replaced by mainFields.
fix
Use mainFields: ['browser', 'module', 'main'] instead of browser: true
deprecated rollup-plugin-node-resolve is deprecated. Use @rollup/plugin-node-resolve instead.
fix Replace with @rollup/plugin-node-resolve and update import: import resolve from '@rollup/plugin-node-resolve';
breaking Option 'jsnext' removed in @rollup/plugin-node-resolve v13; use 'mainFields' instead.
fix Replace jsnext: true with mainFields: ['jsnext:main', 'module', 'main']
gotcha Setting browser: true may cause unexpected module resolution if package.json has a 'browser' map with object entries.
fix Be explicit: use browser field only when targeting browsers. Use a spread of object keys to remap modules.
gotcha preferBuiltins defaults to true, which may cause Node.js built-ins to be treated as external, breaking browser bundles
fix Set preferBuiltins: false when bundling for browsers.
npm install rollup-plugin-bundle-babel
yarn add rollup-plugin-bundle-babel
pnpm add rollup-plugin-bundle-babel

Resolves external npm packages using Node resolution and converts CommonJS modules for Rollup.

import { rollup } from 'rollup';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';

rollup({
  input: 'main.js',
  plugins: [
    nodeResolve({ jsnext: true, main: true }),
    commonjs()
  ]
}).then(bundle => bundle.write({
  file: 'bundle.js',
  format: 'iife',
  name: 'MyModule'
})).catch(err => console.error(err.stack));