@@ -281,7 +281,7 @@ describe('Module syntax detection', { concurrency: !process.env.TEST_PARALLEL },
281281 'const fs = require("node:fs"); await Promise.resolve();' ,
282282 ] ) ;
283283
284- match ( stderr , / R e f e r e n c e E r r o r : r e q u i r e i s n o t d e f i n e d i n E S m o d u l e s c o p e / ) ;
284+ match ( stderr , / E R R _ A M B I G U O U S _ M O D U L E _ S Y N T A X : T h i s f i l e c a n n o t b e p a r s e d a s e i t h e r C o m m o n J S o r E S M o d u l e / ) ;
285285 strictEqual ( stdout , '' ) ;
286286 strictEqual ( code , 1 ) ;
287287 strictEqual ( signal , null ) ;
@@ -423,3 +423,26 @@ describe('when working with Worker threads', () => {
423423 strictEqual ( signal , null ) ;
424424 } ) ;
425425} ) ;
426+
427+ describe ( 'cjs & esm ambiguous syntax case' , async ( ) => {
428+ it ( 'should throw an ambiguous syntax error when using top-level await with require' , async ( ) => {
429+ const { stdout, stderr, code, signal } = await spawnPromisified (
430+ process . execPath ,
431+ [
432+ '--input-type=module' ,
433+ '--eval' ,
434+ `await 1;\nconst fs = require('fs');` ,
435+ ]
436+ ) ;
437+
438+ match ( stderr , / E R R _ A M B I G U O U S _ M O D U L E _ S Y N T A X / ) ;
439+ match ( stderr , / T h i s f i l e c a n n o t b e p a r s e d a s e i t h e r C o m m o n J S o r E S M o d u l e / ) ;
440+ match ( stderr , / a w a i t i s o n l y v a l i d i n a s y n c f u n c t i o n s / ) ;
441+ match ( stderr , / r e q u i r e i s n o t d e f i n e d i n E S m o d u l e s c o p e / ) ;
442+ match ( stderr , / I f y o u m e a n t t o u s e C o m m o n J S / ) ;
443+ match ( stderr , / I f y o u m e a n t t o u s e E S M / ) ;
444+
445+ strictEqual ( code , 1 ) ;
446+ strictEqual ( signal , null ) ;
447+ } ) ;
448+ } ) ;
0 commit comments