Registry / devops / sw-precache-webpack-plugin

sw-precache-webpack-plugin

JSON →
library1.0.0jsnpmunverified

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.

npm install sw-precache-webpack-plugin
INSTALL
IMPORT
SIG · SW-PRECACHE-WEBPAC
S
sw-precache-webpack-plugin
devopsjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SWPrecacheWebpackPlugin
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
import SWPrecacheWebpackPlugin from 'sw-precache-webpack-plugin'
CommonJS default export; not compatible with ESM import syntax. Use require().
SWPrecacheWebpackPlugin
import SWPrecacheWebpackPlugin from 'sw-precache-webpack-plugin'
import { SWPrecacheWebpackPlugin } from 'sw-precache-webpack-plugin'
Default export, not named. Works with ESM if using bundler that allows default from CJS.

Shows basic webpack configuration to generate a service worker using SWPrecacheWebpackPlugin.

const path = require('path'); const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin'); module.exports = { entry: './src/index.js', output: { path: path.resolve(__dirname, 'build'), filename: 'bundle.js', publicPath: '/', }, plugins: [ new SWPrecacheWebpackPlugin({ cacheId: 'my-app', filename: 'service-worker.js', navigateFallback: '/index.html', staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/], minify: true, }), ], };
Debug
Known issues
gotchaPlugin requires webpack 1, 2, 2.1 beta, 2.2 beta, 3, or 4; not compatible with webpack 5+
fix
Migrate to workbox-webpack-plugin for webpack 5 support.
affects: 1.0.0
deprecatedsw-precache-webpack-plugin is no longer maintained and has been superseded by workbox-webpack-plugin
fix
Replace with @angular/service-worker or workbox-webpack-plugin (GenerateSW).
affects: >=0.0.0
gotchaService 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
fix
Set filename option to match desired scope path (e.g., '/service-worker.js').
affects: >=0.0.0
gotchastaticFileGlobsIgnorePatterns must be array of RegExp objects; non-RegExp values cause errors
fix
Use /regex/ pattern literals or new RegExp() objects.
affects: >=0.0.0
breakingPlugin incompatible with webpack 4's output.publicPath change (requires trailing slash) – may cause runtime service worker registration failure
fix
Ensure publicPath ends with '/' and path is absolute.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'sw-precache-webpack-plugin'
Plugin not installed
fix
npm install --save-dev sw-precache-webpack-plugin
TypeError: SWPrecacheWebpackPlugin is not a constructor
Incorrect import or ESM usage without default handling
fix
Use const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin'); or if using ESM, ensure bundler supports default interop.
Invalid or unexpected token (when using options.staticFileGlobsIgnorePatterns)
Non-RegExp value in the array
fix
Use array of RegExp objects, e.g., [/pattern/].
Uncaught (in promise) TypeError: ServiceWorker startup: SecurityError
Service worker file not served from same origin at correct scope
fix
Ensure service-worker.js is placed in the build directory and service worker is registered from the same path.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
webpackrequiredpeer dependency required for plugin functionality
sw-precacheoptionalcore service worker generation library, deprecated itself
Agent activity
7 hits · last 30 days
node
6
Resources
sw-precache-webpack-plugin — npm install sw-precache-webpack-plugin · libregistry