seth
seth
Explore posts from servers
NNuxt
Created by seth on 3/29/2025 in #❓・help
Future-proof way to disable auto-imports of ~/shared?
@kapa.ai when I try to do import whatever from '#shared/foo.js from shared/subfolder/nested.js, I get:
Package import specifier "#shared/foo.js" is not defined in package
Package import specifier "#shared/foo.js" is not defined in package
However, if I do the same import from shared/toplevel.js, it succeeds.
15 replies
NNuxt
Created by seth on 3/29/2025 in #❓・help
Future-proof way to disable auto-imports of ~/shared?
@kapa.ai you said:
You could organize your code like:

shared/
implementations/ # Not auto-imported
feature1.ts
feature2.ts
You could organize your code like:

shared/
implementations/ # Not auto-imported
feature1.ts
feature2.ts
Doesn't code in sub-folder not get built like normal? Wouldn't this mean those files could reference, e.g. '#shared' in their imports and stuff like that?
15 replies
DTDrizzle Team
Created by seth on 3/15/2025 in #help
Stack trace on constraint failed doesn't include my application code
In contrast, throwing an async error inside a nuxt 3 event handler doesn't normally result in a "disconnected" stack trace, for example:
// server/api/session/[id].get.ts

async function throwAsyncError() {
await new Promise(resolve => setTimeout(resolve, 1000))
throw Error('fail in a boring way')
}

export default defineEventHandler(async (event) => {
await throwAsyncError()
})
// server/api/session/[id].get.ts

async function throwAsyncError() {
await new Promise(resolve => setTimeout(resolve, 1000))
throw Error('fail in a boring way')
}

export default defineEventHandler(async (event) => {
await throwAsyncError()
})
Results in the connected stack trace (note the first line references server/api/session[id].get.ts):
ERROR /api/session/01JPCGWVA2M0C2WCM62QZB0V4Y Application error: fail in a boring way

at throwAsyncError (server/api/session/[id].get.ts:40:1)
at async Object.handler (server/api/universal-session/[id].get.ts:44:1)
at async node_modules/h3/dist/index.mjs:2009:19
at async Object.callAsync (node_modules/unctx/dist/index.mjs:72:16)
at async Server.toNodeHandle (node_modules/h3/dist/index.mjs:2301:7)
ERROR /api/session/01JPCGWVA2M0C2WCM62QZB0V4Y Application error: fail in a boring way

at throwAsyncError (server/api/session/[id].get.ts:40:1)
at async Object.handler (server/api/universal-session/[id].get.ts:44:1)
at async node_modules/h3/dist/index.mjs:2009:19
at async Object.callAsync (node_modules/unctx/dist/index.mjs:72:16)
at async Server.toNodeHandle (node_modules/h3/dist/index.mjs:2301:7)
11 replies
DTDrizzle Team
Created by seth on 3/15/2025 in #help
Stack trace on constraint failed doesn't include my application code
Here's a "minimal repro" example with nuxt 3, maybe this will inspire somebody:
// server/api/session/[id].get.ts

import { drizzle } from 'drizzle-orm/libsql'
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core"

const schema = {
universalSessions: sqliteTable("universal_sessions", {
id: text().primaryKey(),
userID: text().notNull(),
createdAt: integer({ mode: "timestamp" }).notNull(),
})
}

export default defineEventHandler(async (event) => {
const universalSessionID = event.context.params?.id
if (!universalSessionID) throw Error("Missing universalSessionID")

const db = drizzle('file:universal.sqlite', {schema})

const universalSession = await db.query.universalSessions.findFirst({
where: (universalSession, { eq }) => eq(universalSession.id, universalSessionID),
with: {
withThingThatDoesntExistToMakeError: true
}
})

console.log("Got universalSession", universalSession)

return universalSession
})
// server/api/session/[id].get.ts

import { drizzle } from 'drizzle-orm/libsql'
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core"

const schema = {
universalSessions: sqliteTable("universal_sessions", {
id: text().primaryKey(),
userID: text().notNull(),
createdAt: integer({ mode: "timestamp" }).notNull(),
})
}

export default defineEventHandler(async (event) => {
const universalSessionID = event.context.params?.id
if (!universalSessionID) throw Error("Missing universalSessionID")

const db = drizzle('file:universal.sqlite', {schema})

const universalSession = await db.query.universalSessions.findFirst({
where: (universalSession, { eq }) => eq(universalSession.id, universalSessionID),
with: {
withThingThatDoesntExistToMakeError: true
}
})

console.log("Got universalSession", universalSession)

return universalSession
})
If I comment out the with(), everything works, its a valid query. The with just makes the query invalid, and it results in a stack trace without the application code in the stack like:
ERROR /api/session/01JPCGWVA2M0C2WCM62QZB0V4Y Application error: Cannot read properties of undefined (reading 'referencedTable')

at normalizeRelation (node_modules/src/relations.ts:571:74)
at SQLiteAsyncDialect.buildRelationalQuery (node_modules/src/sqlite-core/dialect.ts:660:32)
at QueryPromise._toSQL (node_modules/src/sqlite-core/query-builders/query.ts:169:30)
at QueryPromise._prepare (node_modules/src/sqlite-core/query-builders/query.ts:145:38)
at QueryPromise.executeRaw (node_modules/src/sqlite-core/query-builders/query.ts:191:16)
at QueryPromise.execute (node_modules/src/sqlite-core/query-builders/query.ts:197:15)
at QueryPromise.then (node_modules/src/query-promise.ts:31:15)
ERROR /api/session/01JPCGWVA2M0C2WCM62QZB0V4Y Application error: Cannot read properties of undefined (reading 'referencedTable')

at normalizeRelation (node_modules/src/relations.ts:571:74)
at SQLiteAsyncDialect.buildRelationalQuery (node_modules/src/sqlite-core/dialect.ts:660:32)
at QueryPromise._toSQL (node_modules/src/sqlite-core/query-builders/query.ts:169:30)
at QueryPromise._prepare (node_modules/src/sqlite-core/query-builders/query.ts:145:38)
at QueryPromise.executeRaw (node_modules/src/sqlite-core/query-builders/query.ts:191:16)
at QueryPromise.execute (node_modules/src/sqlite-core/query-builders/query.ts:197:15)
at QueryPromise.then (node_modules/src/query-promise.ts:31:15)
11 replies
DTDrizzle Team
Created by seth on 3/15/2025 in #help
Stack trace on constraint failed doesn't include my application code
something nuxt is doing or something I'm doing wrong with nuxt I should say lol
11 replies
DTDrizzle Team
Created by seth on 3/15/2025 in #help
Stack trace on constraint failed doesn't include my application code
Yeah, I suspected the async chain too, I always get a little confused at this point lol. That's why I hoped --trace-uncaught would change things, but no luck. I'm seeing this in another context too, I'm wondering if something nuxt is doing is making this more likely to happen.
11 replies
DTDrizzle Team
Created by seth on 3/15/2025 in #help
Stack trace on constraint failed doesn't include my application code
No prepared statements, although using them is one of my next ideas. Do you ever see this issue, or is this particular to me?
11 replies