@@ -29,6 +29,7 @@ const {
2929 ERR_INVALID_MODULE_SPECIFIER ,
3030 ERR_INVALID_RETURN_PROPERTY_VALUE ,
3131 ERR_INVALID_RETURN_VALUE ,
32+ ERR_MISSING_IMPORT_ASSERTION ,
3233 ERR_UNKNOWN_MODULE_FORMAT
3334} = require ( 'internal/errors' ) . codes ;
3435const { pathToFileURL, isURLInstance } = require ( 'internal/url' ) ;
@@ -48,6 +49,9 @@ const { translators } = require(
4849 'internal/modules/esm/translators' ) ;
4950const { getOptionValue } = require ( 'internal/options' ) ;
5051
52+ const experimentalAssertionlessNonJsImports =
53+ getOptionValue ( '--experimental-import-non-javascript-without-assertion' ) ;
54+
5155const importAssertionTypeCache = new SafeWeakMap ( ) ;
5256const finalFormatCache = new SafeWeakMap ( ) ;
5357const supportedTypes = ObjectFreeze ( [ undefined , 'json' ] ) ;
@@ -252,6 +256,11 @@ class ESMLoader {
252256
253257 if ( job !== undefined ) {
254258 const finalFormat = finalFormatCache . get ( job ) ;
259+ if ( ! experimentalAssertionlessNonJsImports &&
260+ import_assertions . type == null && finalFormat === 'json' ) {
261+ throw new ERR_MISSING_IMPORT_ASSERTION ( url , finalFormat ,
262+ 'type' , 'json' ) ;
263+ }
255264 if (
256265 import_assertions . type == null ||
257266 ( import_assertions . type === 'json' && finalFormat === 'json' )
@@ -268,6 +277,10 @@ class ESMLoader {
268277 throw new ERR_FAILED_IMPORT_ASSERTION (
269278 url , 'type' , import_assertions . type , finalFormat ) ;
270279 }
280+ if ( ! experimentalAssertionlessNonJsImports && finalFormat === 'json' ) {
281+ throw new ERR_MISSING_IMPORT_ASSERTION ( url , finalFormat ,
282+ 'type' , 'json' ) ;
283+ }
271284 finalFormatCache . set ( job , finalFormat ) ;
272285
273286 const translator = translators . get ( finalFormat ) ;
0 commit comments