Skip to content

Commit efeabf9

Browse files
danielroeatinux
andauthored
fix: register vectorize utils even if not running remotely (#396)
Co-authored-by: Sébastien Chopin <[email protected]> Co-authored-by: Sébastien Chopin <[email protected]>
1 parent 67514e8 commit efeabf9

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/features.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ export async function setupAI(nuxt: Nuxt, hub: HubConfig) {
9292
if (nuxt.options.dev && !hub.remote && !hub.projectKey) {
9393
return log.warn('`hubAI()` is disabled: link a project with `npx nuxthub link` to run AI models in development mode.')
9494
}
95+
96+
// Register auto-imports first so types are correct even when not running remotely
97+
addServerImportsDir(resolve('./runtime/ai/server/utils'))
9598
// If we are in dev mode and the project is linked, verify it
9699
if (nuxt.options.dev && !hub.remote && hub.projectKey) {
97100
try {
@@ -115,7 +118,6 @@ export async function setupAI(nuxt: Nuxt, hub: HubConfig) {
115118
}
116119
// Add Server scanning
117120
addServerScanDir(resolve('./runtime/ai/server'))
118-
addServerImportsDir(resolve('./runtime/ai/server/utils'))
119121
}
120122

121123
export function setupAnalytics(_nuxt: Nuxt) {
@@ -134,6 +136,8 @@ export function setupBlob(_nuxt: Nuxt) {
134136
}
135137

136138
export async function setupBrowser(nuxt: Nuxt) {
139+
// Register auto-imports first so types are correct even when not running remotely
140+
addServerImportsDir(resolve('./runtime/browser/server/utils'))
137141
// Check if dependencies are installed
138142
const missingDeps = []
139143
try {
@@ -156,7 +160,6 @@ export async function setupBrowser(nuxt: Nuxt) {
156160
}
157161
// Add Server scanning
158162
// addServerScanDir(resolve('./runtime/browser/server'))
159-
addServerImportsDir(resolve('./runtime/browser/server/utils'))
160163
}
161164

162165
export async function setupCache(nuxt: Nuxt) {
@@ -206,13 +209,14 @@ export function setupKV(_nuxt: Nuxt) {
206209
}
207210

208211
export function setupVectorize(nuxt: Nuxt, hub: HubConfig) {
212+
// Register auto-imports first so types are correct even when not running remotely
213+
addServerImportsDir(resolve('./runtime/vectorize/server/utils'))
209214
if (nuxt.options.dev && !hub.remote) {
210-
log.warn('`hubVectorize()` is disabled: it is currently only supported with `--remote`.')
215+
log.warn('`hubVectorize()` is disabled: only supported with remote storage in development mode.')
211216
return
212217
}
213218
// Add Server scanning
214219
addServerScanDir(resolve('./runtime/vectorize/server'))
215-
addServerImportsDir(resolve('./runtime/vectorize/server/utils'))
216220
}
217221

218222
export function vectorizeRemoteCheck(hub: HubConfig) {

src/runtime/vectorize/server/utils/vectorize.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ export function hubVectorize(index: VectorizeIndexes): Vectorize {
5151
_vectorize[index] = binding as Vectorize
5252
return _vectorize[index]
5353
}
54+
if (import.meta.dev && !hub.remote) {
55+
throw createError({
56+
statusCode: 500,
57+
message: 'hubVectorize() is only supported with remote storage in development mode'
58+
})
59+
}
60+
5461
throw createError(`Missing Cloudflare Vectorize binding (${bindingName})`)
5562
}
5663

0 commit comments

Comments
 (0)