Node ERR_UNSUPPORTED_DIR_IMPORT in CI - Import a File, Not a Directory
ERR_UNSUPPORTED_DIR_IMPORT means native ESM was asked to import a directory. Unlike CommonJS, ESM does not auto-resolve a folder to its index file.
What this error means
A program run as ESM throws Error [ERR_UNSUPPORTED_DIR_IMPORT] for an import that points at a directory rather than a concrete file.
node:internal/modules/esm/resolve:217
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import
'/home/runner/work/app/app/src/utils' is not supported resolving ES modules
at finalizeResolution (node:internal/modules/esm/resolve:217:11)Common causes
Importing a folder under native ESM
ESM does not append /index.js to a directory specifier, so a directory import fails.
A TypeScript directory import not rewritten on emit
Source imports a folder, and the compiler emits the same directory specifier into ESM output.
How to fix it
Import the explicit index file
- Change the directory import to point at the concrete file.
- Include the .js extension.
import { fn } from './utils/index.js';How to prevent it
- Write explicit file paths with extensions in ESM source, avoid directory imports, and configure the compiler to emit resolvable specifiers.