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
- Change the directory import to point at the concrete file.
- 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
Node ERR_MODULE_NOT_FOUND on ESM Import in CI - Fix Specifier ResolutionFix the Node.js ERR_MODULE_NOT_FOUND error in CI by adding the missing file extension or correcting the ESM i…
Node ERR_PACKAGE_PATH_NOT_EXPORTED in CI - Fix the Exports Map SubpathFix the Node.js ERR_PACKAGE_PATH_NOT_EXPORTED error in CI by importing a subpath the package exports map expo…
Node "Cannot find package 'X' imported from" in CI - Fix the ESM Package ResolutionFix the Node.js "Cannot find package X imported from" ESM error in CI by installing the dependency or correct…