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.

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] }
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).
npm install pnp-webpack-plugin
yarn add pnp-webpack-plugin
pnpm add pnp-webpack-plugin

Shows minimal Webpack config adding PnP resolver for both modules and loaders.

const PnpWebpackPlugin = require('pnp-webpack-plugin');

module.exports = {
  resolve: {
    plugins: [PnpWebpackPlugin],
  },
  resolveLoader: {
    plugins: [PnpWebpackPlugin.moduleLoader(module)],
  },
};