diff --git a/lib/internal/modules/esm/formats.js b/lib/internal/modules/esm/formats.js index b081cbe8dd54d5..f56da5de7cbf56 100644 --- a/lib/internal/modules/esm/formats.js +++ b/lib/internal/modules/esm/formats.js @@ -38,7 +38,7 @@ if (experimentalWasmModules) { function mimeToFormat(mime) { if ( RegExpPrototypeExec( - /\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?/i, + /^\s*(text|application)\/javascript\s*(;\s*charset=utf-?8\s*)?$/i, mime, ) !== null ) { return 'module'; } diff --git a/test/es-module/test-esm-invalid-data-urls.js b/test/es-module/test-esm-invalid-data-urls.js index e434c895a2e37d..6eafe75e7d7ed7 100644 --- a/test/es-module/test-esm-invalid-data-urls.js +++ b/test/es-module/test-esm-invalid-data-urls.js @@ -18,4 +18,7 @@ const assert = require('assert'); code: 'ERR_UNKNOWN_MODULE_FORMAT', message: 'Unknown module format: text/css for URL data:text/css,.error { color: red; }', }); + await assert.rejects(import('data:WRONGtext/javascriptFORMAT,console.log("hello!");'), { + code: 'ERR_UNKNOWN_MODULE_FORMAT', + }); })().then(common.mustCall());