Skip to content

Commit 6e0d0fb

Browse files
committed
fix npm build
1 parent b316b44 commit 6e0d0fb

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

__tests__/pages/api/__tests__/getContexts.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ vi.mock('~/pages/api/authorization', () => ({
1313
h,
1414
}))
1515

16-
vi.mock('~/pages/util/fetchContexts', () => ({
16+
vi.mock('~/server/fetchContextsForVectorSearch', () => ({
1717
fetchContextsViaDrizzleVectorSearch:
1818
hoisted.fetchContextsViaDrizzleVectorSearch,
1919
}))

next.config.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const config = {
1818
sizeLimit: '100mb',
1919
},
2020
},
21-
webpack(config) {
21+
webpack(config, { isServer }) {
2222
// Merge existing experiments with the required ones
2323
config.experiments = {
2424
...(config.experiments || {}),
@@ -35,6 +35,16 @@ const config = {
3535
type: 'webassembly/async',
3636
})
3737

38+
// Keep postgres (Node-only; uses tls, net, perf_hooks) out of client bundle. Server uses it via API routes.
39+
if (!isServer) {
40+
config.resolve.fallback = {
41+
...config.resolve?.fallback,
42+
tls: false,
43+
net: false,
44+
perf_hooks: false,
45+
}
46+
}
47+
3848
return config
3949
},
4050

@@ -63,6 +73,8 @@ const config = {
6373
},
6474
experimental: {
6575
esmExternals: false, // To make certain packages work with the /pages router.
76+
// Keep Node-only packages (postgres uses tls, perf_hooks) out of the bundle; required for API routes that use dbClient/vectorSearch.
77+
serverComponentsExternalPackages: ['postgres'],
6678
},
6779
async headers() {
6880
return [

src/pages/api/getContexts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type NextApiResponse } from 'next'
22
import { type AuthenticatedRequest } from '~/utils/authMiddleware'
33
import { withCourseAccessFromRequest } from '~/pages/api/authorization'
4-
import { fetchContextsViaDrizzleVectorSearch } from '~/pages/util/fetchContexts'
4+
import { fetchContextsViaDrizzleVectorSearch } from '~/server/fetchContextsForVectorSearch'
55

66
export default withCourseAccessFromRequest('any')(handler)
77

src/pages/util/fetchContexts.ts renamed to src/server/fetchContextsForVectorSearch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { vectorSearchWithDrizzle } from '~/db/vectorSearch'
33
import { embedQuery } from '~/utils/embedQuery'
44
import { getDocGroupsForVectorSearch } from '~/db/dbHelpers'
55

6-
/** Fetch query embedding (frontend) + doc groups from frontend DB, then run vector search (Drizzle/pgvector). */
6+
/** Fetch query embedding (frontend) + doc groups from frontend DB, then run vector search (Drizzle/pgvector). Server-only. */
77
export async function fetchContextsViaDrizzleVectorSearch(
88
course_name: string,
99
search_query: string,

0 commit comments

Comments
 (0)