pnp-webpack-plugin
raw JSON → 1.7.0 verified Sat Apr 25 auth: no javascript
Webpack plugin for Yarn Plug'n'Play (PnP) resolution, version 1.7.0. It integrates PnP into Webpack's resolver and resolveLoader, allowing dependencies to be resolved from zip archives without node_modules. Updated occasionally; key differentiator: enables PnP in Webpack builds where packages are hoisted into compressed archives, avoiding disk I/O for package resolution. Alternatives include manual resolve.alias configuration or disabling PnP.
Common errors
error Error: Cannot find module 'some-loader' ↓
cause Loader referenced by string name, not require.resolve; PnP cannot resolve it.
fix
Use require.resolve('some-loader') in the loader option.
error Module not found: Error: Can't resolve 'some-package' ↓
cause PnP resolver not configured in resolve.plugins.
fix
Add PnpWebpackPlugin to resolve.plugins in webpack config.
error TypeError: PnpWebpackPlugin is not a constructor ↓
cause Using new PnpWebpackPlugin() instead of direct reference.
fix
Remove 'new' keyword: resolve: { plugins: [PnpWebpackPlugin] }
Warnings
gotcha When using PnP, loaders must be resolved via require.resolve() in webpack config rules to avoid resolution failures. ↓
fix Replace loader name string with require.resolve('loader-name').
deprecated The package is not actively maintained; Webpack 5 may require alternative integration. ↓
fix Consider using @yarnpkg/pnpify or webpack's built-in PnP support.
gotcha Does not resolve loaders inside node_modules automatically; moduleLoader must be used. ↓
fix Always add resolveLoader.plugins with PnpWebpackPlugin.moduleLoader(module).
Install
npm install pnp-webpack-plugin yarn add pnp-webpack-plugin pnpm add pnp-webpack-plugin Imports
- default plugin wrong
import PnpWebpackPlugin from 'pnp-webpack-plugin';correctconst PnpWebpackPlugin = require('pnp-webpack-plugin'); - moduleLoader wrong
PnpWebpackPlugin.moduleLoader()correctPnpWebpackPlugin.moduleLoader(module) - PnpWebpackPlugin as WebpackPluginInstance wrong
new PnpWebpackPlugin()correctPnpWebpackPlugin
Quickstart
const PnpWebpackPlugin = require('pnp-webpack-plugin');
module.exports = {
resolve: {
plugins: [PnpWebpackPlugin],
},
resolveLoader: {
plugins: [PnpWebpackPlugin.moduleLoader(module)],
},
};