{"id":15055,"library":"webpack-delete-sourcemaps-plugin","title":"Webpack Delete Sourcemaps Plugin","description":"The `webpack-delete-sourcemaps-plugin` is a Webpack plugin designed to automatically remove sourcemap files at the conclusion of a build process. This is particularly useful for workflows involving services like Sentry, where sourcemaps are uploaded for error tracking but should not be exposed on production servers due to security risks (source code disclosure). The current stable version is `1.3.1`, with recent updates indicating active maintenance, including improvements for Webpack 4 compatibility since `v1.3.0`. A key differentiator is its explicit handling of the `devtool: 'hidden-source-map'` configuration to prevent browsers from requesting non-existent sourcemaps, and providing tailored guidance for integration with Next.js and Sentry.","status":"active","version":"1.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/AlexBeauchemin/webpack-delete-sourcemaps-plugin","tags":["javascript","webpack","webpack5","sourcemap","sentry","nextjs","next","plugin","typescript"],"install":[{"cmd":"npm install webpack-delete-sourcemaps-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add webpack-delete-sourcemaps-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add webpack-delete-sourcemaps-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for any Webpack plugin. Version 1.3.0 introduced compatibility with Webpack 4 via optional dependencies, while the README states primary compatibility with Webpack 5.","package":"webpack","optional":false}],"imports":[{"note":"While CommonJS `require` works, ESM `import` is preferred for modern projects and TypeScript.","wrong":"const DeleteSourceMapsPlugin = require('webpack-delete-sourcemaps-plugin');","symbol":"DeleteSourceMapsPlugin","correct":"import { DeleteSourceMapsPlugin } from 'webpack-delete-sourcemaps-plugin';"},{"note":"Aliasing the import can help avoid naming conflicts, especially if another plugin uses a similar name.","symbol":"DeleteSourceMapsPlugin as Plugin","correct":"import { DeleteSourceMapsPlugin as Plugin } from 'webpack-delete-sourcemaps-plugin';"}],"quickstart":{"code":"import { DeleteSourceMapsPlugin } from 'webpack-delete-sourcemaps-plugin';\nimport type { Configuration } from 'webpack';\n\ninterface NextWebpackConfigOptions {\n  isServer: boolean;\n  dev: boolean;\n  // ... other Next.js specific options\n}\n\n// Basic Webpack Configuration Example\nconst webpackConfig: Configuration = {\n  mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',\n  devtool: 'hidden-source-map', // Recommended to prevent 404s for deleted sourcemaps\n  entry: './src/index.js',\n  output: {\n    filename: '[name].js',\n    path: __dirname + '/dist',\n    clean: true\n  },\n  plugins: [\n    new DeleteSourceMapsPlugin({\n      // Optional: keepServerSourcemaps: true\n      // Optional: silent: true\n    })\n  ]\n};\n\n// Example with Next.js (in next.config.js)\nconst nextConfigWebpack = (config: Configuration, options: NextWebpackConfigOptions) => {\n  // For Next.js, 'hidden-source-map' is often managed by sentry-webpack-plugin\n  // This plugin can override it for client builds if necessary.\n  config.plugins?.push(\n    new DeleteSourceMapsPlugin({\n      isServer: options.isServer,\n      keepServerSourcemaps: true, // Typically keep sourcemaps for server builds in Next.js\n      silent: process.env.CI === 'true' // Reduce console output in CI/CD\n    })\n  );\n  return config;\n};\n\n// In a real setup, you'd export these configs appropriately.\n// For demonstration purposes:\nconsole.log('Webpack configuration for deletion plugin:', webpackConfig);\n// console.log('Next.js webpack config callback:', nextConfigWebpack);","lang":"typescript","description":"Demonstrates basic Webpack integration and advanced usage within a Next.js configuration, emphasizing `hidden-source-map` and server-side sourcemap retention."},"warnings":[{"fix":"Ensure `webpack-delete-sourcemaps-plugin` is correctly configured in your production Webpack build to delete sourcemaps after any upload steps (e.g., to Sentry).","message":"Exposing sourcemap files on production servers can be a security risk, allowing attackers to view original source code. This plugin addresses that by enabling post-build deletion.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set `devtool: 'hidden-source-map'` in your Webpack configuration. For Next.js, the plugin can handle overriding `devtool` for client builds, even when `sentry-webpack-plugin` is used.","message":"After deleting sourcemaps, browsers might still attempt to fetch them if references remain in the bundled JavaScript files, leading to 404 errors. The plugin helps address this, but `devtool: 'hidden-source-map'` is crucial.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to `webpack-delete-sourcemaps-plugin@1.3.0` or newer if you require Webpack 4 support. Ensure your Webpack setup matches the plugin's stated compatibility.","message":"Prior to version 1.3.0, the plugin explicitly stated compatibility only with Webpack 5. While v1.3.0 introduced optional compatibility with Webpack 4, using older versions of the plugin with Webpack 4 or earlier will likely lead to errors.","severity":"breaking","affected_versions":"<1.3.0"},{"fix":"Pass the `isServer` flag from your `next.config.js` webpack callback to the plugin, and consider `keepServerSourcemaps: true` if you need them for server-side debugging or error reporting.","message":"When integrating with Next.js, it's common to differentiate between server-side and client-side builds. The `isServer` option is vital to ensure server sourcemaps are handled (often kept) correctly.","severity":"gotcha","affected_versions":">=1.2.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Run `npm install webpack-delete-sourcemaps-plugin --save-dev` or `yarn add webpack-delete-sourcemaps-plugin --dev`.","cause":"The package was not installed or is not resolvable in the current environment.","error":"Cannot find module 'webpack-delete-sourcemaps-plugin'"},{"fix":"Ensure `devtool: 'hidden-source-map'` is set in your Webpack configuration. The plugin helps manage this, especially for Next.js builds.","cause":"Sourcemap files were deleted, but the bundled JavaScript still contains references, causing the browser to attempt to load them.","error":"GET http://localhost:3000/static/js/main.js.map 404 (Not Found)"},{"fix":"Use a named import: `import { DeleteSourceMapsPlugin } from 'webpack-delete-sourcemaps-plugin';` or `const { DeleteSourceMapsPlugin } = require('webpack-delete-sourcemaps-plugin');`","cause":"Incorrect import statement; attempting to call the module as a default export or using incorrect destructuring.","error":"TypeError: DeleteSourceMapsPlugin is not a constructor"}],"ecosystem":"npm"}