unbuild
unbuild copied to clipboard
`rollup:options` in hooks throw error when `options.plugins = [ options.plugins ]`
trafficstars
Environment
node: v20.9.0
pnpm: 8.15.4
"typescript": "^5.4.2",
Reproduction
github repo
pnpm i
pnpm build
It will throw error.
Describe the bug
See build.config.ts in the mini-repo above.
The option of defineBuildConfig will throw error:
export default defineBuildConfig({
// ...
hooks: {
'rollup:options': (_, options) => {
options.plugins = [
options.plugins,
]
},
},
})
Cannot read properties of undefined (reading '_options')
// Locate this line of code
shebangPlugin2._options.preserve = false;
But Vitejs use code like it, refer to Vite Repo
And the type also looks it should work:
type InputPluginOption = MaybePromise<Plugin | NullValue | false | InputPluginOption[]>
Additional context
No response
Logs
ERROR Error building D:/Code/test/unbuildErrTest: TypeError: Cannot read properties of undefined (reading '_options') 23:25:55
ERROR Cannot read properties of undefined (reading '_options') 23:25:55
at rollupBuild (/D:/Code/test/unbuildErrTest/node_modules/.pnpm/[email protected][email protected]/node_modules/unbuild/dist/index.mjs:696:20)
at async _build (/D:/Code/test/unbuildErrTest/node_modules/.pnpm/[email protected][email protected]/node_modules/unbuild/dist/index.mjs:1087:3)
at async build (/D:/Code/test/unbuildErrTest/node_modules/.pnpm/[email protected][email protected]/node_modules/unbuild/dist/index.mjs:945:5)
at async Object.run (/D:/Code/test/unbuildErrTest/node_modules/.pnpm/[email protected][email protected]/node_modules/unbuild/dist/cli.mjs:63:5)
at async runCommand (/D:/Code/test/unbuildErrTest/node_modules/.pnpm/[email protected]/node_modules/citty/dist/index.mjs:316:16)
at async runMain (/D:/Code/test/unbuildErrTest/node_modules/.pnpm/[email protected]/node_modules/citty/dist/index.mjs:445:7)