@@ -47,7 +47,7 @@ describe('ESM in main field', { concurrency: !process.env.TEST_PARALLEL }, () =>
4747 assert . strictEqual ( code , 0 ) ;
4848 } ) ;
4949
50- it ( 'should emit warning when "main" and "exports" are missing' , async ( ) => {
50+ it ( 'should throw when "main" and "exports" are missing' , async ( ) => {
5151 const cwd = tmpdir . resolve ( Math . random ( ) . toString ( ) ) ;
5252 const pkgPath = path . join ( cwd , './node_modules/pkg/' ) ;
5353 await mkdir ( pkgPath , { recursive : true } ) ;
@@ -60,11 +60,12 @@ describe('ESM in main field', { concurrency: !process.env.TEST_PARALLEL }, () =>
6060 '--eval' , 'import "pkg"' ,
6161 ] , { cwd } ) ;
6262
63- assert . match ( stderr , / \[ D E P 0 1 5 1 \] / ) ;
64- assert . match ( stdout , / ^ H e l l o W o r l d ! \r ? \n $ / ) ;
65- assert . strictEqual ( code , 0 ) ;
63+ assert . match ( stderr , / E R R _ I N V A L I D _ P A C K A G E _ C O N F I G / ) ;
64+ assert . match ( stderr , / D e f a u l t " i n d e x " l o o k u p s f o r t h e m a i n a r e n o t s u p p o r t e d f o r E S m o d u l e s / ) ;
65+ assert . strictEqual ( stdout , '' ) ;
66+ assert . strictEqual ( code , 1 ) ;
6667 } ) ;
67- it ( 'should emit warning when "main" is falsy' , async ( ) => {
68+ it ( 'should throw when "main" is falsy' , async ( ) => {
6869 const cwd = tmpdir . resolve ( Math . random ( ) . toString ( ) ) ;
6970 const pkgPath = path . join ( cwd , './node_modules/pkg/' ) ;
7071 await mkdir ( pkgPath , { recursive : true } ) ;
@@ -78,11 +79,12 @@ describe('ESM in main field', { concurrency: !process.env.TEST_PARALLEL }, () =>
7879 '--eval' , 'import "pkg"' ,
7980 ] , { cwd } ) ;
8081
81- assert . match ( stderr , / \[ D E P 0 1 5 1 \] / ) ;
82- assert . match ( stdout , / ^ H e l l o W o r l d ! \r ? \n $ / ) ;
83- assert . strictEqual ( code , 0 ) ;
82+ assert . match ( stderr , / E R R _ I N V A L I D _ P A C K A G E _ C O N F I G / ) ;
83+ assert . match ( stderr , / D e f a u l t " i n d e x " l o o k u p s f o r t h e m a i n a r e n o t s u p p o r t e d f o r E S m o d u l e s / ) ;
84+ assert . strictEqual ( stdout , '' ) ;
85+ assert . strictEqual ( code , 1 ) ;
8486 } ) ;
85- it ( 'should emit warning when "main" is a relative path without extension' , async ( ) => {
87+ it ( 'should throw when "main" is a relative path without extension' , async ( ) => {
8688 const cwd = tmpdir . resolve ( Math . random ( ) . toString ( ) ) ;
8789 const pkgPath = path . join ( cwd , './node_modules/pkg/' ) ;
8890 await mkdir ( pkgPath , { recursive : true } ) ;
@@ -96,11 +98,12 @@ describe('ESM in main field', { concurrency: !process.env.TEST_PARALLEL }, () =>
9698 '--eval' , 'import "pkg"' ,
9799 ] , { cwd } ) ;
98100
99- assert . match ( stderr , / \[ D E P 0 1 5 1 \] / ) ;
100- assert . match ( stdout , / ^ H e l l o W o r l d ! \r ? \n $ / ) ;
101- assert . strictEqual ( code , 0 ) ;
101+ assert . match ( stderr , / E R R _ I N V A L I D _ P A C K A G E _ C O N F I G / ) ;
102+ assert . match ( stderr , / A u t o m a t i c e x t e n s i o n r e s o l u t i o n o f t h e " m a i n " f i e l d i s n o t s u p p o r t e d / ) ;
103+ assert . strictEqual ( stdout , '' ) ;
104+ assert . strictEqual ( code , 1 ) ;
102105 } ) ;
103- it ( 'should emit warning when "main" is an absolute path without extension' , async ( ) => {
106+ it ( 'should throw when "main" is an absolute path without extension' , async ( ) => {
104107 const cwd = tmpdir . resolve ( Math . random ( ) . toString ( ) ) ;
105108 const pkgPath = path . join ( cwd , './node_modules/pkg/' ) ;
106109 await mkdir ( pkgPath , { recursive : true } ) ;
@@ -114,7 +117,23 @@ describe('ESM in main field', { concurrency: !process.env.TEST_PARALLEL }, () =>
114117 '--eval' , 'import "pkg"' ,
115118 ] , { cwd } ) ;
116119
117- assert . match ( stderr , / \[ D E P 0 1 5 1 \] / ) ;
120+ assert . match ( stderr , / E R R _ I N V A L I D _ P A C K A G E _ C O N F I G / ) ;
121+ assert . match ( stderr , / A u t o m a t i c e x t e n s i o n r e s o l u t i o n o f t h e " m a i n " f i e l d i s n o t s u p p o r t e d / ) ;
122+ assert . strictEqual ( stdout , '' ) ;
123+ assert . strictEqual ( code , 1 ) ;
124+ } ) ;
125+ it ( 'should still resolve CommonJS packages via index lookup' , async ( ) => {
126+ const cwd = tmpdir . resolve ( Math . random ( ) . toString ( ) ) ;
127+ const pkgPath = path . join ( cwd , './node_modules/pkg/' ) ;
128+ await mkdir ( pkgPath , { recursive : true } ) ;
129+ await writeFile ( path . join ( pkgPath , './index.js' ) , 'console.log("Hello World!")' ) ;
130+ await writeFile ( path . join ( pkgPath , './package.json' ) , JSON . stringify ( { } ) ) ;
131+ const { code, stdout, stderr } = await spawnPromisified ( execPath , [
132+ '--input-type=module' ,
133+ '--eval' , 'import "pkg"' ,
134+ ] , { cwd } ) ;
135+
136+ assert . strictEqual ( stderr , '' ) ;
118137 assert . match ( stdout , / ^ H e l l o W o r l d ! \r ? \n $ / ) ;
119138 assert . strictEqual ( code , 0 ) ;
120139 } ) ;
0 commit comments