11import createMDX from '@next/mdx'
22import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin'
33import type { NextConfig } from 'next'
4+ import type { Configuration } from 'webpack'
45
56const nextConfig : NextConfig = {
67 pageExtensions : [ 'js' , 'jsx' , 'md' , 'mdx' , 'ts' , 'tsx' ] ,
@@ -38,7 +39,7 @@ const nextConfig: NextConfig = {
3839 typedRoutes : false ,
3940 reactStrictMode : true ,
4041 distDir : '.next' ,
41- webpack : ( config , { isServer } ) => {
42+ webpack : ( config : Configuration , { isServer } ) => {
4243 if ( ! isServer ) {
4344 config . plugins = config . plugins ?? [ ]
4445 config . plugins . push (
@@ -52,10 +53,55 @@ const nextConfig: NextConfig = {
5253 ] ,
5354 } )
5455 )
56+
57+ // Sanitize resolve.alias so values are serializable for Turbopack/worker cloning
58+ // Ensure resolve exists and normalize alias values to strings/arrays of strings
59+ const existingResolve = config . resolve ?? { }
60+ const aliasObj = ( existingResolve as unknown as Record < string , unknown > ) . alias ?? { }
61+ if ( typeof aliasObj === 'object' && aliasObj !== null ) {
62+ const normalized : Record < string , string | string [ ] > = { }
63+ for ( const [ k , v ] of Object . entries ( aliasObj as Record < string , unknown > ) ) {
64+ if ( Array . isArray ( v ) ) {
65+ normalized [ k ] = v . map ( ( x ) => String ( x ) )
66+ } else if ( typeof v === 'object' && v !== null ) {
67+ // For objects, stringify to avoid '[object Object]' implicit string coercion
68+ try {
69+ normalized [ k ] = JSON . stringify ( v )
70+ } catch {
71+ normalized [ k ] = ''
72+ }
73+ } else if ( typeof v === 'function' ) {
74+ // For functions, prefer the function name to avoid serializing the entire function
75+ // Narrow to an object with an optional name property to avoid using the broad Function type
76+ const fnName = ( v as { name ?: string } ) ?. name ?? ''
77+ normalized [ k ] = fnName
78+ } else if ( v === null || v === undefined ) {
79+ // Keep null/undefined normalized to an empty string
80+ normalized [ k ] = ''
81+ } else {
82+ // At this point, expect primitives (string/number/boolean/symbol/bigint).
83+ // Guard against objects to avoid default Object stringification '[object Object]'.
84+ const t = typeof v
85+ if ( t === 'string' || t === 'number' || t === 'boolean' || t === 'symbol' || t === 'bigint' ) {
86+ // Narrow the type for the linter to avoid base-to-string coercion warnings
87+ normalized [ k ] = String ( v as string | number | boolean | symbol | bigint )
88+ } else {
89+ // Fallback for unexpected non-serializable values
90+ try {
91+ normalized [ k ] = JSON . stringify ( v )
92+ } catch {
93+ normalized [ k ] = ''
94+ }
95+ }
96+ }
97+ }
98+ config . resolve = { ...existingResolve , alias : normalized } as Configuration [ 'resolve' ]
99+ }
55100 }
56101
57102 return config
58103 } ,
104+
59105 typescript : {
60106 ignoreBuildErrors : true ,
61107 tsconfigPath : './tsconfig.json' ,
@@ -92,7 +138,7 @@ const nextConfig: NextConfig = {
92138 // optimizeCss: true,
93139 esmExternals : true ,
94140 scrollRestoration : true ,
95- // cpus: 16,
141+ // cpus: 16,
96142 // cssChunking: true,
97143 // craCompat: true,
98144 // validateRSCRequestHeaders: true,
0 commit comments