Skip to content

Bug: ERR_UNSUPPORTED_ESM_URL_SCHEME on Windows when using codecept.conf.ts #5581

@mmaaxi

Description

@mmaaxi

What are you trying to achieve?

Run npx codeceptjs check to validate a TypeScript configuration file (codecept.conf.ts) on Windows.

What do you get instead?

The command fails with ERR_UNSUPPORTED_ESM_URL_SCHEME. CodeceptJS 4 transpiles the .ts config to a temp .js file and then calls import(tempFile) with a raw Windows absolute path (e.g. c:\Users\...\tempXXXX.js). The Node.js ESM loader on Windows only accepts file:// URLs — it treats c: as an unsupported URL scheme and throws.

Root cause

The issue is in lib/config.js line 245 (and 261):

configModule = await import(tempFile) // tempFile = "c:\Users\...\tempXXXX.js" on Windows

Proposed fix — convert the path to a file:// URL before importing:

import { pathToFileURL } from 'url'
// ...
configModule = await import(pathToFileURL(tempFile).href)

This issue only affects Windows. Unix absolute paths (/home/...) are accepted by the ESM loader, while Windows drive-letter paths (c:\...) are not.

Console output

√ CONFIG Framework
Global functions are deprecated. Use `import { Helper, within, session } from "codeceptjs"` instead. Set `noGlobals: true` in config to disable globals.
Error: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
    at throwIfUnsupportedURLScheme (node:internal/modules/esm/load:241:11)
    at defaultLoad (node:internal/modules/esm/load:132:3)
    at ModuleLoader.load (node:internal/modules/esm/loader:724:12)
    at ModuleLoader.loadAndTranslate (node:internal/modules/esm/loader:543:56)
    at ModuleLoader.#createModuleJob (node:internal/modules/esm/loader:567:36)
    at ModuleLoader.#getJobFromResolveResult (node:internal/modules/esm/loader:297:34)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:265:41)
    at async ModuleLoader.import (node:internal/modules/esm/loader:605:23) {
  code: 'ERR_UNSUPPORTED_ESM_URL_SCHEME'
}

Test source code

N/A — the error occurs during config loading, before any test runs.

Details

Field Value
CodeceptJS version 4.0.2
NodeJS Version 20.20.2
Operating System Windows 11 Pro
playwright version 1.39.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions