{"id":20811,"library":"webpack-pnp-externals","title":"Webpack PnP Externals","description":"Webpack plugin (v1.1.0) to exclude Yarn Plug'n'Play (PnP) modules from the bundle, intended for backend bundles using Yarn PnP. Works with Webpack 4 and 5. It complements webpack-node-externals by resolving PnP packages to their virtual locators, preventing bundling of dependencies that should be loaded at runtime. It supports include/exclude filters and custom import types. Lightweight, no runtime dependencies. Minimal maintenance frequency as of 2023.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/jonhartnett/webpack-pnp-externals","tags":["javascript"],"install":[{"cmd":"npm install webpack-pnp-externals","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-pnp-externals","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-pnp-externals","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for externals configuration","package":"webpack","optional":false}],"imports":[{"note":"Package is CJS-only; ES modules import syntax will fail. Use require or dynamic import().","wrong":"import WebpackPnpExternals from 'webpack-pnp-externals'","symbol":"WebpackPnpExternals","correct":"const { WebpackPnpExternals } = require('webpack-pnp-externals')"},{"note":"The package exports a named export 'WebpackPnpExternals' which is a function. Default import is not provided.","wrong":"const { default: WebpackPnpExternals } = require('webpack-pnp-externals')","symbol":"default","correct":"const WebpackPnpExternals = require('webpack-pnp-externals')"},{"note":"TypeScript users: this package has no type definitions. Declare module or use @types/webpack-pnp-externals if available.","wrong":"","symbol":"WebpackPnpExternals","correct":"import { WebpackPnpExternals } from 'webpack-pnp-externals'"}],"quickstart":{"code":"const { WebpackPnpExternals } = require('webpack-pnp-externals');\n\nmodule.exports = {\n  target: 'node',\n  externals: [\n    WebpackPnpExternals({\n      include: /^lodash/,\n      exclude: ['lodash.omit'],\n      importType: 'commonjs2'\n    })\n  ]\n};","lang":"javascript","description":"Shows how to use WebpackPnpExternals in webpack config to externalize Yarn PnP packages with include/exclude filters and custom import type."},"warnings":[{"fix":"Use WebpackPnpExternals() with parentheses, not WebpackPnpExternals.","message":"WebpackPnpExternals() must be called (returning a function) in the externals array; passing the reference without invoking will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For Yarn Berry, consider using webpack-plugin-yarn-pnp-externals or manually configuring externals with locator logic.","message":"Only works with Yarn Classic (v1) PnP; Yarn Berry (v2+) has different PnP resolution that is not supported.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use RegExp for substring matching, e.g., include: /^lodash/.","message":"The 'include' and 'exclude' options can be a string, RegExp, function, or array. Using a string matches the request exactly, not a substring.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to Webpack 5 for full compatibility.","message":"Webpack 4 is no longer supported by the package explicitly; but it still works. No deprecation warnings.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install: npm install -D webpack-pnp-externals","cause":"Package not installed or not in node_modules.","error":"Error: Cannot find module 'webpack-pnp-externals'"},{"fix":"Use require syntax: const { WebpackPnpExternals } = require('webpack-pnp-externals');","cause":"Using import statement in CJS context, or misspelling the import.","error":"TypeError: WebpackPnpExternals is not a function"},{"fix":"Check that options.include/exclude are valid types; ensure WebpackPnpExternals() is called with parentheses.","cause":"WebpackPnpExternals() returned a non-standard value, likely due to invalid options.","error":"Error: Externals function must return a string, array, or object."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}