Repository navigation
build-html crash (undefined.call) when transformIndexHtml is registered in object form (breaks vite-plugin-pwa) #3188
Description
Describe the bug
Describe the bug
vp build fails with TypeError: Cannot read properties of undefined (reading 'call') from applyHtmlTransforms whenever a plugin registers transformIndexHtml in the object form (the Vite 5+ convention). vite-plugin-pwa (and likely other mainstream plugins) does exactly this, so the build is broken out of the box for any project using PWA.
Reproduction
Minimal repro with any custom plugin using the object form:
// vite.config.js
export default {
plugins: [
{
name: 'repro',
transformIndexHtml: {
transform(html) {
return html;
},
},
},
],
};Or simply add vite-plugin-pwa to the plugins.
Expected behavior
The build succeeds and the transformIndexHtml hook is invoked.
Actual behavior
error during build:
Build failed with 1 error:
[plugin vite:build-html]
TypeError: Cannot read properties of undefined (reading 'call')
at applyHtmlTransforms (.../vite-plus-core/dist/vite/node/chunks/node.js:37604:26)
at PluginContextImpl.generateBundle (.../vite-plus-core/dist/vite/node/chunks/node.js:37392:20)
Root cause
In @voidzero-dev/vite-plus-core@1.3.0, resolveHtmlTransforms reads the object-form hook via hook.handler:
function resolveHtmlTransforms(plugins) {
// ...
const hook = plugin.transformIndexHtml;
if (!hook) continue;
if (typeof hook === "function") normalHooks.push(hook);
else {
const handler = hook.handler; // ← should be hook.transform
if (hook.order === "pre") preHooks.push(handler);
else if (hook.order === "post") postHooks.push(handler);
else normalHooks.push(handler);
}
}Since Vite 5, the object form of transformIndexHtml uses the transform key (not handler). Plugins that register { transform(html, ctx) {...}, enforce: 'post' } (e.g. vite-plugin-pwa) therefore push undefined into the hooks array. applyHtmlTransforms then calls hook.call(pluginContext, html, ctx) on undefined and throws.
Suggested fix
const handler = hook.transform ?? hook.handler;Optionally also map enforce/apply to pre/post ordering, mirroring Vite core semantics.
Environment
@voidzero-dev/vite-plus: 1.3.0 (core 1.3.0)- Bundled Vite: 8.3.4, rolldown 1.2.14
vite-plugin-pwa: 1.3.0- Node: 20.19+ / 22
- OS: Windows 11 (reproducible cross-platform)
Workaround
Locally patch node_modules/@voidzero-dev/vite-plus-core/dist/vite/node/chunks/node.js:
const handler = hook.transform ?? hook.handler;Reproduction
https://gist.github.com/journeybyte/b116b514fcd59cf5f97728b41581a515
Steps to reproduce
- npm i -D vite-plus@1.3.0 in any project
- Create vite.config.js with the plugin from the gist (object-form transformIndexHtml)
- Run
vp build - Build fails with
TypeError: Cannot read properties of undefined (reading 'call')fromapplyHtmlTransforms
System Info
$ vp --version
vp v1.3.0
Local vite-plus:
vite-plus v1.3.0
Tools:
vite v8.3.4
rolldown v1.2.14
vitest v5.0.5
oxfmt v0.73.0
oxlint v1.88.0
oxlint-tsgolint v7.0.2004
tsdown v0.23.1
$ vp env current
Node.js:
Version 24.22.1
Source engines.node
Bin Path C:\Users\Zhang\AppData\Local\vite-plus\data\js_runtime\node\24.22.1\node.exe
Installed false
Mode managed
Package Manager:
Name pnpm
Version 12.14.0
Source lockfile or config
Bin Paths
pnpm C:\Users\Zhang\AppData\Local\vite-plus\data\package_manager\pnpm\12.14.0\pnpm\bin\pnpm.exe
pnpx C:\Users\Zhang\AppData\Local\vite-plus\data\package_manager\pnpm\12.14.0\pnpm\bin\pnpx.exe
Installed true
Mode managedUsed Package Manager
pnpm
Logs
$ vp build --debug
error during build:
Build failed with 1 error:
[plugin vite:build-html]
TypeError: Cannot read properties of undefined (reading 'call')
at applyHtmlTransforms (@voidzero-dev/vite-plus-core/dist/vite/node/chunks/node.js:37604:26)
at PluginContextImpl.generateBundle (@voidzero-dev/vite-plus-core/dist/vite/node/chunks/node.js:37392:20)Validations
- Read the Contributing Guidelines.
- Check that there isn't already an issue for the same bug.
- Confirm this is a Vite+ issue and not an upstream issue (Vite, Vitest, tsdown, Rolldown, or Oxc).
- The provided reproduction is a minimal reproducible example.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Effort
Target date
Start date
Activity
jong-kyung commentedon Oct 22, 2026
Vite+ currently uses Vite 8, which requires handler instead of transform in the object form of transformIndexHtml. Could you try changing it to handler and let us know if the issue persists?