1- import { readFile } from 'fs/promises' ;
2- import { join } from 'path' ;
3-
41/** @type {import('next').NextConfig } */
5- const nextConfig = {
6- webpack : config => {
7- config . externals . push ( {
8- '@supabase/realtime-js' : 'commonjs @supabase/realtime-js' ,
9- } ) ;
10-
11- // Handling large JSON files by reading them at build time
12- const templatesPath = join ( process . cwd ( ) , 'lib' , 'templates.json' ) ;
13- config . plugins . push (
14- new ( class {
15- apply ( compiler ) {
16- compiler . hooks . thisCompilation . tap (
17- 'InjectTemplatesPlugin' ,
18- compilation => {
19- compilation . hooks . processAssets . tapAsync (
20- {
21- name : 'InjectTemplatesPlugin' ,
22- stage :
23- compilation . PROCESS_ASSETS_STAGE_ADDITIONAL ,
24- } ,
25- async ( assets , callback ) => {
26- try {
27- const templatesContent = await readFile (
28- templatesPath ,
29- 'utf-8' ,
30- ) ;
31- const templatesJson = JSON . stringify (
32- JSON . parse ( templatesContent ) ,
33- ) ;
34- const assetId = 'lib/templates.json' ;
35- assets [ assetId ] = {
36- source : ( ) => `export default ${ templatesJson } ` ,
37- size : ( ) => templatesJson . length ,
38- } ;
39- callback ( ) ;
40- } catch ( error ) {
41- callback ( error ) ;
42- }
43- } ,
44- ) ;
45- } ,
46- ) ;
47- }
48- } ) ( ) ,
49- ) ;
502
51- return config ;
52- } ,
3+ const nextConfig = {
534 env : {
545 SANDBOX_ID : 'ina8cw5gcg0ts1as7iz7o-5b7f1102' ,
556 } ,
@@ -69,6 +20,28 @@ const nextConfig = {
6920 } ,
7021 ] ;
7122 } ,
23+ webpack : ( config , { isServer, webpack } ) => {
24+ // The "Critical dependency: the request of a dependency is an expression" warning
25+ // often originates from libraries like @supabase /realtime-js when they use
26+ // dynamic requires or imports that Webpack cannot statically analyze.
27+
28+ // If this warning appears during server-side bundling (e.g., for API routes, as in this case),
29+ // making @supabase /realtime-js external can resolve it. This means Node.js
30+ // will require() it at runtime instead of Webpack trying to bundle it.
31+ // This is generally safe if its real-time client features aren't actively used
32+ // in the server-side context where it's imported.
33+ if ( isServer ) {
34+ config . externals = [ ...config . externals , '@supabase/realtime-js' ] ;
35+ }
36+
37+ // Additionally, @supabase/realtime-js or its dependencies (like WebSocket libraries)
38+ // might try to optionally include native modules like 'bufferutil' and 'utf-8-validate'.
39+ // Making these external tells Webpack not to bundle them and can prevent related warnings.
40+ // This is a common fix for issues involving the 'ws' package or similar.
41+ config . externals . push ( 'bufferutil' , 'utf-8-validate' ) ;
42+
43+ return config ;
44+ } ,
7245} ;
7346
74- export default nextConfig ;
47+ export default nextConfig ;
0 commit comments