{"id":20606,"library":"targets-webpack-plugin","title":"targets-webpack-plugin","description":"Webpack plugin that uses Babel to transpile output bundles for legacy browsers, including dependencies. Version 4.0.0 requires Node >=8. Unlike other solutions (e.g., babel-loader applied per file), it runs transpilation once per asset at the end of compilation, reducing build time. Key differentiator: it handles dependency transpilation automatically and supports custom browser targets via the Browserslist ecosystem.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/sheerun/targets-webpack-plugin","tags":["javascript"],"install":[{"cmd":"npm install targets-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add targets-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add targets-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for plugin integration","package":"webpack","optional":false}],"imports":[{"note":"The package does not export a default ES module; CommonJS require is required.","wrong":"import TargetsPlugin from 'targets-webpack-plugin';","symbol":"TargetsPlugin","correct":"const TargetsPlugin = require('targets-webpack-plugin');"}],"quickstart":{"code":"// next.config.js\nconst TargetsPlugin = require('targets-webpack-plugin');\n\nmodule.exports = {\n  webpack: function (config, { dev }) {\n    if (!dev) {\n      config.plugins.push(new TargetsPlugin({\n        browsers: ['last 2 versions', 'chrome >= 41']\n      }));\n    }\n    return config;\n  }\n};","lang":"javascript","description":"Configures the TargetsPlugin in a Next.js webpack config to transpile production bundles for legacy browsers."},"warnings":[{"fix":"Check that the plugin is only added when process.env.NODE_ENV === 'production' or similar.","message":"Plugin only transpiles in production mode when 'dev' is false; ensure correct conditional.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install webpack: npm install webpack --save-dev","message":"Requires webpack as a peer dependency; missing webpack will cause runtime errors.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Use object with 'browsers' key or rely on browserslist config file.","message":"The 'browsers' option uses Browserslist; older configs may reference 'browserslist' array directly.","severity":"deprecated","affected_versions":"<4.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run npm install --save-dev targets-webpack-plugin","cause":"Package not installed in node_modules.","error":"Error: Cannot find module 'targets-webpack-plugin'"},{"fix":"Replace import with: const TargetsPlugin = require('targets-webpack-plugin');","cause":"Using ES module import instead of CommonJS require.","error":"TypeError: TargetsPlugin is not a constructor"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}