rollup-plugin-pnp-resolve
raw JSON → 2.0.0 verified Mon Apr 27 auth: no javascript
A Rollup plugin that resolves modules using Yarn's Plug'n'Play (PnP) API instead of the traditional node_modules resolution. Version 2.0.0 requires Node >=6 and supports Rollup's plugin system. It forwards options to PnP's resolveRequest, such as custom extensions. This plugin is part of a family of PnP resolvers for various tools including TypeScript (ts-pnp), Webpack (pnp-webpack-plugin), and Jest (jest-pnp-resolver). Unlike traditional resolvers, it directly uses the PnP dependency tree for faster and more reliable resolution in Yarn PnP projects, eliminating the need for node_modules.
Common errors
error Error: Cannot find module 'rollup-plugin-pnp-resolve' ↓
cause Package not installed or Yarn PnP not enabled.
fix
Ensure the package is installed with Yarn PnP (yarn add -D rollup-plugin-pnp-resolve) and that you are using Yarn PnP (not node_modules).
error TypeError: pnpResolve is not a function ↓
cause Using default import in CommonJS or incorrect import syntax.
fix
In CommonJS: const pnpResolve = require('rollup-plugin-pnp-resolve'). In ESM: import pnpResolve from 'rollup-plugin-pnp-resolve'.
error Error: Plugin returned something but it is not a valid plugin. ↓
cause Calling pnpResolve without invoking it as a function (i.e., passing the function instead of calling it).
fix
Use pnpResolve() in plugins array, not pnpResolve.
Warnings
gotcha The plugin must be placed after rollup-plugin-commonjs in the plugins array to ensure CommonJS modules are transformed before resolution. ↓
fix Order plugins: commonjs() first, then pnpResolve().
breaking Version 2.0.0 dropped support for Rollup <1.0.0 and changed the API to a function that returns a plugin object. ↓
fix Update Rollup to >=1.0.0 and ensure plugin is invoked as a function (e.g., pnpResolve()).
deprecated The package may not be actively maintained; Yarn's PnP support is now built into Yarn's own Rollup plugin and other official tools. ↓
fix Consider using @yarnpkg/plugin-rollup for official Yarn PnP integration.
gotcha Options passed to pnpResolve are forwarded to PnP's resolveRequest; not all options may be supported. ↓
fix Consult PnP API documentation for valid options (e.g., extensions, basedir).
Install
npm install rollup-plugin-pnp-resolve yarn add rollup-plugin-pnp-resolve pnpm add rollup-plugin-pnp-resolve Imports
- default wrong
const pnpResolve = require('rollup-plugin-pnp-resolve').defaultcorrectimport pnpResolve from 'rollup-plugin-pnp-resolve' - default (CommonJS) wrong
const { resolve } = require('rollup-plugin-pnp-resolve')correctconst resolve = require('rollup-plugin-pnp-resolve') - Rollup Plugin wrong
plugins: [new pnpResolve()]correctplugins: [pnpResolve({ extensions: ['.js'] })]
Quickstart
// rollup.config.js
import pnpResolve from 'rollup-plugin-pnp-resolve';
import commonjs from 'rollup-plugin-commonjs';
export default {
input: 'src/index.js',
output: {
dir: 'dist',
format: 'cjs',
},
plugins: [
commonjs(),
pnpResolve({ extensions: ['.js', '.jsx'] })
]
};