{"id":22429,"library":"sw-precache-webpack-plugin","title":"sw-precache-webpack-plugin","description":"Webpack plugin (v1.0.0) that generates a service worker file using sw-precache to cache external project dependencies. Abandoned since 2019; no longer updated with new webpack versions. Key differentiator: simple integration for service worker caching in webpack builds, but superseded by workbox-webpack-plugin which is actively maintained and more feature-rich. Handles automatic cache busting, minification, and navigation fallback. Last stable release was 2017; requires Node >=4.","status":"abandoned","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/goldhand/sw-precache-webpack-plugin","tags":["javascript","webpack","plugin","precache","sw-precache","service","worker"],"install":[{"cmd":"npm install sw-precache-webpack-plugin","lang":"bash","label":"npm"},{"cmd":"yarn add sw-precache-webpack-plugin","lang":"bash","label":"yarn"},{"cmd":"pnpm add sw-precache-webpack-plugin","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for plugin functionality","package":"webpack","optional":false},{"reason":"core service worker generation library, deprecated itself","package":"sw-precache","optional":true}],"imports":[{"note":"CommonJS default export; not compatible with ESM import syntax. Use require().","wrong":"import SWPrecacheWebpackPlugin from 'sw-precache-webpack-plugin'","symbol":"SWPrecacheWebpackPlugin","correct":"const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')"},{"note":"Default export, not named. Works with ESM if using bundler that allows default from CJS.","wrong":"import { SWPrecacheWebpackPlugin } from 'sw-precache-webpack-plugin'","symbol":"SWPrecacheWebpackPlugin","correct":"import SWPrecacheWebpackPlugin from 'sw-precache-webpack-plugin'"}],"quickstart":{"code":"const path = require('path');\nconst SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');\n\nmodule.exports = {\n  entry: './src/index.js',\n  output: {\n    path: path.resolve(__dirname, 'build'),\n    filename: 'bundle.js',\n    publicPath: '/',\n  },\n  plugins: [\n    new SWPrecacheWebpackPlugin({\n      cacheId: 'my-app',\n      filename: 'service-worker.js',\n      navigateFallback: '/index.html',\n      staticFileGlobsIgnorePatterns: [/\\.map$/, /asset-manifest\\.json$/],\n      minify: true,\n    }),\n  ],\n};","lang":"javascript","description":"Shows basic webpack configuration to generate a service worker using SWPrecacheWebpackPlugin."},"warnings":[{"fix":"Migrate to workbox-webpack-plugin for webpack 5 support.","message":"Plugin requires webpack 1, 2, 2.1 beta, 2.2 beta, 3, or 4; not compatible with webpack 5+","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Replace with @angular/service-worker or workbox-webpack-plugin (GenerateSW).","message":"sw-precache-webpack-plugin is no longer maintained and has been superseded by workbox-webpack-plugin","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Set filename option to match desired scope path (e.g., '/service-worker.js').","message":"Service worker filename defaults to service-worker.js and is placed in webpack output.path; scope is determined by directory, so ensure file is served from correct path","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use /regex/ pattern literals or new RegExp() objects.","message":"staticFileGlobsIgnorePatterns must be array of RegExp objects; non-RegExp values cause errors","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure publicPath ends with '/' and path is absolute.","message":"Plugin incompatible with webpack 4's output.publicPath change (requires trailing slash) – may cause runtime service worker registration failure","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"npm install --save-dev sw-precache-webpack-plugin","cause":"Plugin not installed","error":"Error: Cannot find module 'sw-precache-webpack-plugin'"},{"fix":"Use const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin'); or if using ESM, ensure bundler supports default interop.","cause":"Incorrect import or ESM usage without default handling","error":"TypeError: SWPrecacheWebpackPlugin is not a constructor"},{"fix":"Use array of RegExp objects, e.g., [/pattern/].","cause":"Non-RegExp value in the array","error":"Invalid or unexpected token (when using options.staticFileGlobsIgnorePatterns)"},{"fix":"Ensure service-worker.js is placed in the build directory and service worker is registered from the same path.","cause":"Service worker file not served from same origin at correct scope","error":"Uncaught (in promise) TypeError: ServiceWorker startup: SecurityError"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}