GeezerVison is showing github.com — esm: throw `ERR_REQUIRE_ESM` instead of `ERR_INTERNAL_ASSERTION` · nodejs/node@a624002
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/modules/esm/loader.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -326,8 +326,6 @@ class ModuleLoader { |
326 | 326 | * @returns {ModuleJobBase} |
327 | 327 | */ |
328 | 328 | getModuleJobForRequire(specifier, parentURL, importAttributes) { |
329 | | - assert(getOptionValue('--experimental-require-module')); |
330 | | - |
331 | 329 | const parsed = URLParse(specifier); |
332 | 330 | if (parsed != null) { |
333 | 331 | const protocol = parsed.protocol; |
@@ -346,6 +344,9 @@ class ModuleLoader { |
346 | 344 | } |
347 | 345 |
|
348 | 346 | const { url, format } = resolveResult; |
| 347 | + if (!getOptionValue('--experimental-require-module')) { |
| 348 | + throw new ERR_REQUIRE_ESM(url, true); |
| 349 | + } |
349 | 350 | const resolvedImportAttributes = resolveResult.importAttributes ?? importAttributes; |
350 | 351 | let job = this.loadCache.get(url, resolvedImportAttributes.type); |
351 | 352 | if (job !== undefined) { |
|
Collapse file
Copy file name to clipboardExpand all lines: test/es-module/test-typescript.mjs +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,6 +28,18 @@ test('execute a TypeScript file with imports', async () => { |
28 | 28 | strictEqual(result.code, 0); |
29 | 29 | }); |
30 | 30 |
|
| 31 | +test('execute a TypeScript file with imports', async () => { |
| 32 | + const result = await spawnPromisified(process.execPath, [ |
| 33 | + '--no-warnings', |
| 34 | + '--eval', |
| 35 | + `assert.throws(() => require(${JSON.stringify(fixtures.path('typescript/ts/test-import-fs.ts'))}), {code: 'ERR_REQUIRE_ESM'})`, |
| 36 | + ]); |
| 37 | + |
| 38 | + strictEqual(result.stderr, ''); |
| 39 | + strictEqual(result.stdout, ''); |
| 40 | + strictEqual(result.code, 0); |
| 41 | +}); |
| 42 | + |
31 | 43 | test('execute a TypeScript file with imports with default-type module', async () => { |
32 | 44 | const result = await spawnPromisified(process.execPath, [ |
33 | 45 | '--experimental-strip-types', |
|