vite-plugin-pwa: Error running plugin hook closeBundle for vite-plugin-pwa:build, expected a function hook.
App build fails with this error.

vite.config.ts
// ...
build: {
outDir: 'build',
emptyOutDir: true,
},
plugins: [
react(),
svgrPlugin({ svgrOptions: { icon: true } }),
tsconfigPaths(),
VitePWA({
devOptions: { enabled: !isBuild },
registerType: 'autoUpdate',
manifest,
workbox,
outDir: 'build',
}),
],
// ...
yarn dev works fine, but dev-dist/sw.js only precaches index.html no other js,css files.
yarn build fails with above error. rest of the build works fine, bundles are generated but no sw.js gets generated in the build folder.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (7 by maintainers)
@RohitKaushal7 from version 0.13.0 you need Vite 3.1+: https://github.com/vite-pwa/vite-plugin-pwa#-install
@RohitKaushal7 you can try with v0.12.8 without upgrading Vite to 3.1+:
"vite-plugin-pwa": "0.12.8"@ls so something installed on your local, here my deps:
Well, it looks like I’m going to have to figure out why this is here. Thanks for helping debug!
We have a yarn resolution to use this version of rollup… no idea why that is yet.
Hey, I fixed those issues with vite 3.1.5. Thank you.
I am using
NodeGlobalsPolyfillPluginto accessBufferandprocess.changed these imports to import from
distotherwise vite was importing fromsrcoresmfolder and then cryingCannot use import outside module.