@@ -69,6 +69,7 @@ if ((v8 as any)?.startupSnapshot?.isBuildingSnapshot?.()) {
6969// eslint-disable-next-line complexity
7070async function main ( ) {
7171 markTime ( TimingCategories . Main , 'entered main' ) ;
72+ suppressExperimentalWarnings ( ) ;
7273 if ( process . env . MONGOSH_RUN_NODE_SCRIPT ) {
7374 // For uncompiled mongosh: node /path/to/this/file script ... -> node script ...
7475 // FOr compiled mongosh: mongosh mongosh script ... -> mongosh script ...
@@ -311,3 +312,32 @@ async function ask(prompt: string): Promise<string> {
311312 process . stdin . unpipe ( stdinCopy ) ;
312313 }
313314}
315+
316+ /**
317+ * Helper to suppress experimental warnings emitted by node if necessary.
318+ *
319+ * In Node.js 23 require()ing ESM modules will work, but emit an experimental warning like
320+ * CommonJS module ABC is loading ES Module XYZ using require(). This is causing problems for
321+ * the way we import fetch - see relevant comments here:
322+ * https://github.com/mongodb-js/devtools-shared/blob/29ceeb5f51d29883d4a69c83e68ad37b0965d49e/packages/devtools-proxy-support/src/fetch.ts#L12-L17
323+ */
324+ function suppressExperimentalWarnings ( ) {
325+ const nodeMajorVersion = process . versions . node . split ( '.' ) . map ( Number ) [ 0 ] ;
326+ if ( nodeMajorVersion >= 23 ) {
327+ const originalEmit = process . emitWarning ;
328+ process . emitWarning = ( warning , ...args : any [ ] ) : void => {
329+ if ( args [ 0 ] === 'ExperimentalWarning' ) {
330+ return ;
331+ }
332+
333+ if (
334+ typeof args [ 0 ] === 'object' &&
335+ args [ 0 ] . type === 'ExperimentalWarning'
336+ ) {
337+ return ;
338+ }
339+
340+ return originalEmit ( warning , ...args ) ;
341+ } ;
342+ }
343+ }
0 commit comments