Skip to content
Latchkey

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
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

  1. Change the directory import to point at the concrete file.
  2. Include the .js extension.
JavaScript
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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →