Skip to content

CodeceptJS v4 cannot load config on Windows #5588

Closed

Description

@danielrentz

CodeceptJS fails to load config file on Windows (tried in powershell and git bash):

$ pnpm codeceptjs run
Error: Failed to load config file C:\test\e2e\codecept.conf.js:
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 loadConfigFile (file:///C:/test/e2e/node_modules/.pnpm/codeceptjs@4.0.2_@types+node@25.9.0/node_modules/codeceptjs/lib/config.js:272:15)
    at async Config.load (file:///C:/test/e2e/node_modules/.pnpm/codeceptjs@4.0.2_@types+node@25.9.0/node_modules/codeceptjs/lib/config.js:124:16)
    at async getConfig (file:///C:/test/e2e/node_modules/.pnpm/codeceptjs@4.0.2_@types+node@25.9.0/node_modules/codeceptjs/lib/command/utils.js:16:12)
    at async default (file:///C:/test/ui/e2e/node_modules/.pnpm/codeceptjs@4.0.2_@types+node@25.9.0/node_modules/codeceptjs/lib/command/run.js:19:16)
    at async Command.<anonymous> (file:///C:/test/e2e/node_modules/.pnpm/codeceptjs@4.0.2_@types+node@25.9.0/node_modules/codeceptjs/bin/codecept.js:40:7)

passing a file URL fails as well:

$ pnpm codeceptjs run -c "file:///C:/test/e2e/codecept.config.js"
Error: Config file C:\test\e2e\file:\C:\test\e2e\codecept.config.js does not exist. Execute 'codeceptjs init' to create config

Activity

  1. danielrentz commented on May 29, 2026

    @danielrentz
    ContributorAuthor

    Same happens when loading plugins:

    Error: Could not load plugin from 'C:\test\e2e\plugins\plugin.ts': 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 loadPluginAsync (file:///C:/test/e2e/node_modules/.pnpm/codeceptjs@4.0.2_@types+node@25.6.2/node_modules/codeceptjs/lib/container.js:688:11)
        at async createPlugins (file:///C:/test/e2e/node_modules/.pnpm/codeceptjs@4.0.2_@types+node@25.6.2/node_modules/codeceptjs/lib/container.js:755:29)
        at async Container.create (file:///C:/test/e2e/node_modules/.pnpm/codeceptjs@4.0.2_@types+node@25.6.2/node_modules/codeceptjs/lib/container.js:81:25)
        at async Codecept.init (file:///C:/test/e2e/node_modules/.pnpm/codeceptjs@4.0.2_@types+node@25.6.2/node_modules/codeceptjs/lib/codecept.js:105:5)
  2. kobenguyent commented on Jun 3, 2026

    @kobenguyent
    Collaborator

    @danielrentz may you help check if #5595 resolves the windows issues?

  3. danielrentz commented on Jun 3, 2026

    @danielrentz
    ContributorAuthor

    @kobenguyent No it still crashes in line 262 of lib/config.js when loading codecept.config.js

            // Try ESM import first for JS files
            configModule = await import(configFile)
  4. kobenguyent commented on Jun 3, 2026

    @kobenguyent
    Collaborator

    @danielrentz thanks for testing. Maybe we have luck with this d735b33

  5. danielrentz commented on Jun 4, 2026

    @danielrentz
    ContributorAuthor

    @kobenguyent I just applied the entire patch (yesterday just the bits for lib/config.js), and it already fails in bin/codecept.js in "dynamicImport", where the absolute path check is missing, causing to resolve relative internal paths against cwd.

    May I suggest to move the full check with "isWindows" and "isAbsolutePath" into an own util function and call it everywhere? It would not hurt but would increase safety if code places always expecting abolute paths would check them as well.

  6. danielrentz commented on Jun 4, 2026

    @danielrentz
    ContributorAuthor

    I found more places missing the "isAbsolute" path check:

    • "loadPluginAsync" in lib/container.js (line 707)
    • "runHooks" in lib/codecept.js (line 140)

    After fixing these three places locally, the tests run again.

    Strong argument for the util function, right? :)

  7. kobenguyent commented on Jun 4, 2026

    @kobenguyent
    Collaborator

    @danielrentz Indeed, thanks for the suggestion. I'm thinking the same cause in the beginning just thought there are one or two places needed for those patches but turned out more. Utils is definitely a great approach though. 👍🏻

    Really appreciated if you could test this out #5595

  8. danielrentz commented on Jun 4, 2026

    @danielrentz
    ContributorAuthor

    @kobenguyent It works!

    Two remarks:

    • In lib/codecept.js, the new import path from 'path' (line35) is now unused.
    • The changes in test/unit/container_test.js do not make much sense, path.isAbsolute('../data/dummy_page.js') is always false.
  9. kobenguyent commented on Jun 8, 2026

    @kobenguyent
    Collaborator

    supposed to be fixed by https://github.com/codeceptjs/CodeceptJS/releases/tag/4.0.4. Closing for now. Don't hesitate to report back if something still broken. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions