@@ -231,10 +231,10 @@ const prepareJsonAttributes = (
231231} ;
232232
233233const isCommonJsRequireContext = (
234- context : Parameters < LoadHook > [ 1 ] ,
234+ { conditions } : Parameters < LoadHook > [ 1 ] ,
235235) => (
236- context . conditions . includes ( 'require' )
237- && ! context . conditions . includes ( 'import' )
236+ conditions ? .includes ( 'require' ) === true
237+ && ! conditions . includes ( 'import' )
238238) ;
239239
240240export const createLoad = (
@@ -361,6 +361,9 @@ export const createLoad = (
361361 }
362362
363363 const code = loaded . source . toString ( ) ;
364+ // CJS JSON require still parses hook source as JSON after module hooks.
365+ // https://github.com/nodejs/node/blob/v24.15.0/lib/internal/modules/cjs/loader.js#L1969-L1978
366+ const shouldTransformJson = loadedFormat === 'json' && ! isCommonJsRequireContext ( context ) ;
364367
365368 if ( loadedFormat === 'commonjs-typescript' ) {
366369 const transformed = transformSync (
@@ -380,7 +383,7 @@ export const createLoad = (
380383
381384 if (
382385 // Support named imports in JSON modules
383- loaded . format === 'json'
386+ shouldTransformJson
384387 || isModuleTypeScriptFormat ( loadedFormat )
385388 || tsExtensionsPattern . test ( url )
386389 ) {
@@ -509,6 +512,9 @@ export const createLoadSync = (
509512 }
510513
511514 const code = loaded . source . toString ( ) ;
515+ // CJS JSON require still parses hook source as JSON after module hooks.
516+ // https://github.com/nodejs/node/blob/v24.15.0/lib/internal/modules/cjs/loader.js#L1969-L1978
517+ const shouldTransformJson = loadedFormat === 'json' && ! isCommonJsRequireContext ( context ) ;
512518
513519 if ( loadedFormat === 'commonjs-typescript' ) {
514520 const transformed = transformSync (
@@ -529,7 +535,7 @@ export const createLoadSync = (
529535
530536 if (
531537 // Support named imports in JSON modules
532- loaded . format === 'json'
538+ shouldTransformJson
533539 || isModuleTypeScriptFormat ( loadedFormat )
534540 || tsExtensionsPattern . test ( url )
535541 ) {
0 commit comments