Skip to content

Commit 6e3b606

Browse files
committed
fix(kit): add default values for destructured references in addTypeTemplate hooks
Fixes issue where nodeReferences, sharedReferences, and references arrays could be undefined when destructured in prepare:types and nitro:prepare:types hooks, causing 'Cannot read properties of undefined (reading "push")' errors. This ensures backward compatibility by providing empty arrays as defaults when the hook payload doesn't contain these properties.
1 parent 0b1129e commit 6e3b606

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/kit/src/template.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ export function addTypeTemplate<T> (_template: NuxtTypeTemplate<T>, context?: {
8080

8181
// Add template to types reference
8282
if (!context || context.nuxt) {
83-
nuxt.hook('prepare:types', ({ references }) => {
83+
nuxt.hook('prepare:types', ({ references = [] }) => {
8484
references.push({ path: template.dst })
8585
})
8686
}
8787
if (context?.node) {
88-
nuxt.hook('prepare:types', ({ nodeReferences }) => {
88+
nuxt.hook('prepare:types', ({ nodeReferences = [] }) => {
8989
nodeReferences.push({ path: template.dst })
9090
})
9191
}
9292
if (context?.shared) {
93-
nuxt.hook('prepare:types', ({ sharedReferences }) => {
93+
nuxt.hook('prepare:types', ({ sharedReferences = [] }) => {
9494
sharedReferences.push({ path: template.dst })
9595
})
9696
}
@@ -105,7 +105,7 @@ export function addTypeTemplate<T> (_template: NuxtTypeTemplate<T>, context?: {
105105
}
106106

107107
if (context?.nitro) {
108-
nuxt.hook('nitro:prepare:types', ({ references }) => {
108+
nuxt.hook('nitro:prepare:types', ({ references = [] }) => {
109109
references.push({ path: template.dst })
110110
})
111111
}

0 commit comments

Comments
 (0)