Parcourir la source

fix: resolve Docker build failure by excluding Node.js modules

- Add postgres and drizzle-orm to serverExternalPackages to prevent bundling Node.js-only modules (net, tls, crypto, stream, perf_hooks)
- Set CI=true in Dockerfile to skip instrumentation database connections during build
- Fixes Module not found errors for Node.js built-in modules during Next.js build
claude[bot] il y a 4 mois
Parent
commit
c175285cc9
2 fichiers modifiés avec 12 ajouts et 1 suppressions
  1. 2 0
      deploy/Dockerfile
  2. 10 1
      next.config.ts

+ 2 - 0
deploy/Dockerfile

@@ -21,6 +21,8 @@ ENV NEXT_PUBLIC_APP_VERSION=$APP_VERSION
 # 这些是占位符,实际运行时会被真实值覆盖
 ENV DSN="postgres://placeholder:placeholder@localhost:5432/placeholder"
 ENV REDIS_URL="redis://localhost:6379"
+# 标记为 CI 环境,跳过 instrumentation.ts 中的数据库连接
+ENV CI=true
 
 RUN bun run build
 

+ 10 - 1
next.config.ts

@@ -12,7 +12,16 @@ const nextConfig: NextConfig = {
 
   // 排除服务端专用包(避免打包到客户端)
   // bull 和相关依赖只在服务端使用,包含 Node.js 原生模块
-  serverExternalPackages: ["bull", "bullmq", "@bull-board/api", "@bull-board/express", "ioredis"],
+  // postgres 和 drizzle-orm 包含 Node.js 原生模块(net, tls, crypto, stream, perf_hooks)
+  serverExternalPackages: [
+    "bull",
+    "bullmq",
+    "@bull-board/api",
+    "@bull-board/express",
+    "ioredis",
+    "postgres",
+    "drizzle-orm",
+  ],
 
   // 强制包含 undici 到 standalone 输出
   // Next.js 依赖追踪无法正确追踪动态导入和类型导入的传递依赖