@@ -1340,11 +1340,31 @@ function loadESMFromCJS(mod, filename) {
13401340 // ESM won't be accessible via process.mainModule.
13411341 setOwnProperty ( process , 'mainModule' , undefined ) ;
13421342 } else {
1343- emitExperimentalWarning ( 'Support for loading ES Module in require()' ) ;
1343+ const parent = mod [ kModuleParent ] ;
1344+ let messagePrefix ;
1345+ if ( parent ) {
1346+ // In the case of the module calling `require()`, it's more useful to know its absolute path.
1347+ let from = parent . filename || parent . id ;
1348+ // In the case of the module being require()d, it's more useful to know the id passed into require().
1349+ const to = mod . id || mod . filename ;
1350+ if ( from === 'internal/preload' ) {
1351+ from = '--require' ;
1352+ } else if ( from === '<repl>' ) {
1353+ from = 'The REPL' ;
1354+ } else if ( from === '.' ) {
1355+ from = 'The entry point' ;
1356+ } else {
1357+ from &&= `CommonJS module ${ from } ` ;
1358+ }
1359+ if ( from && to ) {
1360+ messagePrefix = `${ from } is loading ES Module ${ to } using require().\n` ;
1361+ }
1362+ }
1363+ emitExperimentalWarning ( 'Support for loading ES Module in require()' , messagePrefix ) ;
13441364 const {
13451365 wrap,
13461366 namespace,
1347- } = cascadedLoader . importSyncForRequire ( mod , filename , source , isMain , mod [ kModuleParent ] ) ;
1367+ } = cascadedLoader . importSyncForRequire ( mod , filename , source , isMain , parent ) ;
13481368 // Tooling in the ecosystem have been using the __esModule property to recognize
13491369 // transpiled ESM in consuming code. For example, a 'log' package written in ESM:
13501370 //
0 commit comments