Skip to content

Commit b9fcd98

Browse files
efekrsklpdeveltere
andcommitted
loader: add plain text mime type
Co-authored-by: pdeveltere <pdeveltere@users.noreply.github.com>
1 parent 4c1debd commit b9fcd98

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/internal/modules/esm/get_format.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ function mimeToFormat(mime) {
4747
) { return 'module'; }
4848
if (mime === 'application/json') { return 'json'; }
4949
if (mime === 'application/wasm') { return 'wasm'; }
50+
if (
51+
getOptionValue('--experimental-import-text') &&
52+
RegExpPrototypeExec(
53+
/^\s*text\/plain\s*(;\s*charset=utf-?8\s*)?$/i,
54+
mime,
55+
) !== null
56+
) { return 'text'; }
5057
return null;
5158
}
5259

test/es-module/test-esm-import-text.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ assert.match(jsonAsText.default, /"im broken"/);
4242

4343
await assert.rejects(
4444
import('data:text/plain,hello%20world'),
45-
{ code: 'ERR_UNKNOWN_MODULE_FORMAT' },
45+
{ code: 'ERR_IMPORT_ATTRIBUTE_MISSING' },
4646
);
4747

4848
await assert.rejects(

0 commit comments

Comments
 (0)