Errors
ERR_UNKNOWN_FILE_EXTENSION
The ESM loader does not support the resolved file extension under the current configuration. Use a documented module format or a reviewed loader. Tested on Node.js 22.16.0. Example output (one line per entry): ["ERR_UNKNOWN_FILE_EXTENSION", "1"].
Formal Syntax & Structure
nodejs syntaxnodejs
error.code === "ERR_UNKNOWN_FILE_EXTENSION"Return Value
Error
Observed error classification; successful correction has its own return value.
Working Example
Example Snippetnodejs
import { mkdtemp, writeFile, rm, mkdir, readFile, stat } from 'node:fs/promises';import { join } from 'node:path';import { tmpdir } from 'node:os';import { pathToFileURL } from 'node:url';const d = await mkdtemp(join(tmpdir(), 'bytemind-'));try { const bad = join(d, 'sample.unknown'), good = join(d, 'sample.mjs'); await writeFile(bad, 'export default 1'); try { await import(pathToFileURL(bad)); } catch (e) { console.log(e.code); } await writeFile(good, 'export default 1'); console.log((await import(pathToFileURL(good))).default);}finally { await rm(d, { recursive: true, force: true });}