@@ -3,22 +3,23 @@ const nextConfig = {
3
3
// 启用standalone构建(用于Docker)
4
4
output : 'standalone' ,
5
5
6
- // 禁用分享页面的根布局继承
7
- layoutSegments : {
8
- share : {
9
- inheritParentLayout : false
10
- }
11
- } ,
12
-
13
6
// 启用流式响应
14
7
experimental : {
15
- serverActions : true ,
16
- serverComponents : true ,
17
8
typedRoutes : true ,
18
9
} ,
19
10
20
- // 将过时的配置移到新位置
21
- serverExternalPackages : [ '@prisma/client' , 'mysql2' , 'canvas' , 'vm2' , 'degenerator' , 'pac-resolver' ] ,
11
+ // 外部包配置 - 基于 urllib PR #457 的修复思路
12
+ serverExternalPackages : [
13
+ '@prisma/client' ,
14
+ 'mysql2' ,
15
+ 'canvas' ,
16
+ // 避免 vm2 安全漏洞相关的包
17
+ 'vm2' ,
18
+ 'degenerator' ,
19
+ 'pac-resolver' ,
20
+ 'pac-proxy-agent' ,
21
+ 'proxy-agent'
22
+ ] ,
22
23
23
24
// 配置图片处理
24
25
images : {
@@ -37,6 +38,48 @@ const nextConfig = {
37
38
38
39
typescript : {
39
40
ignoreBuildErrors : true ,
41
+ } ,
42
+
43
+ // Webpack 配置 - 基于 urllib 避免 vm2 依赖的策略
44
+ webpack : ( config , { isServer } ) => {
45
+ // 为所有有安全问题的模块添加 fallback
46
+ config . resolve . fallback = {
47
+ ...config . resolve . fallback ,
48
+ // 核心安全问题模块
49
+ 'vm2' : false ,
50
+ 'coffee-script' : false ,
51
+ 'degenerator' : false ,
52
+ // 代理相关模块 (参考 urllib PR #457)
53
+ 'pac-resolver' : false ,
54
+ 'pac-proxy-agent' : false ,
55
+ 'proxy-agent' : false ,
56
+ } ;
57
+
58
+ // 服务器端外部化这些模块
59
+ if ( isServer ) {
60
+ config . externals = config . externals || [ ] ;
61
+
62
+ // 添加条件外部化,只在模块存在时才外部化
63
+ const problematicModules = [
64
+ 'vm2' ,
65
+ 'coffee-script' ,
66
+ 'degenerator' ,
67
+ 'pac-resolver' ,
68
+ 'pac-proxy-agent' ,
69
+ 'proxy-agent'
70
+ ] ;
71
+
72
+ problematicModules . forEach ( module => {
73
+ config . externals . push ( ( { request } , callback ) => {
74
+ if ( request === module ) {
75
+ return callback ( null , `commonjs ${ module } ` ) ;
76
+ }
77
+ callback ( ) ;
78
+ } ) ;
79
+ } ) ;
80
+ }
81
+
82
+ return config ;
40
83
}
41
84
}
42
85
0 commit comments