Skip to content
Latchkey

Node "ERR_UNSUPPORTED_DIR_IMPORT: Directory import not supported" in CI

Native ESM does not resolve a directory to its index.js the way CommonJS does. Importing a folder path throws ERR_UNSUPPORTED_DIR_IMPORT; you must import the file directly.

What this error means

An import that points at a directory, like import x from "./utils" where utils/ is a folder, fails with "Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import ... is not supported resolving ES modules".

node
node:internal/modules/esm/resolve:... Error [ERR_UNSUPPORTED_DIR_IMPORT]:
Directory import '/app/src/utils' is not supported resolving ES modules imported from
/app/src/index.js
Did you mean to import "./utils/index.js"?

Common causes

Importing a folder instead of a file

CommonJS would load utils/index.js, but ESM has no directory resolution, so the folder specifier is unsupported.

Barrel imports written as folder paths

A re-export barrel referenced as ./components (a directory) needs the explicit index.js under ESM.

How to fix it

Import the index file explicitly

Point the import at the actual entry file, including the extension.

index.js
import { helper } from './utils/index.js';

Expose a subpath via package exports

For a published package, map the folder to a file through the exports field so the short specifier resolves.

package.json
{
  "exports": { "./utils": "./src/utils/index.js" }
}

How to prevent it

  • Always import the concrete index.js, not the directory, in ESM.
  • Use the exports map to provide clean subpaths for consumers.
  • Remember ESM has no implicit index resolution.

Related guides

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