Skip to content

[Bug]: --config <file> fails with "Could not find a config file" when the cwd has no discoverable config (jest-config >= 30.5.1) #16457

Open

Description

@Silic0nS0ldier

Version

30.5.1

Steps to reproduce

mkdir -p /tmp/proj/sub && cd /tmp/proj
npm i -D [email protected]
cat > sub/custom.config.mjs <<'EOF'
export default { rootDir: '.', testMatch: ['**/*.spec.js'] };
EOF
echo "test('ok', () => expect(1).toBe(1));" > sub/a.spec.js
# run from a directory that has NO package.json / jest.config.* in it or any ancestor:
cd "$(mktemp -d)"
/tmp/proj/node_modules/.bin/jest --ci --runInBand --config /tmp/proj/sub/custom.config.mjs

Expected behavior

Tests run successfully.

Actual behavior

An error is raised, stating that a config file could not be found.

Error: Could not find a config file based on provided values:
path: "/tmp/tmp.uprzWmvUzT"
cwd: "/tmp/tmp.uprzWmvUzT"
Config paths must be specified by either a direct path to a config
file, or a path to a directory. If directory is given, Jest will try to
traverse directory tree up, until it finds one of those files in exact order: "jest.config.js" or "jest.config.ts" or "jest.config.mjs" or "jest.config.mts" or "jest.config.cjs" or "jest.config.cts" or "jest.config.json".
    at resolveConfigPathByTraversing (/tmp/proj/node_modules/jest-config/build/index.js:2596:11)
    at resolveConfigPathByTraversing (/tmp/proj/node_modules/jest-config/build/index.js:2600:10)
    at resolveConfigPathByTraversing (/tmp/proj/node_modules/jest-config/build/index.js:2600:10)
    at resolveConfigPath (/tmp/proj/node_modules/jest-config/build/index.js:2567:10)
    at /tmp/proj/node_modules/jest-config/build/index.js:1246:163
    at Array.map (<anonymous>)
    at readConfigs (/tmp/proj/node_modules/jest-config/build/index.js:1240:8)
    at async runCLI (/tmp/proj/node_modules/@jest/core/build/index.js:1420:7)
    at async Object.run (/tmp/proj/node_modules/jest-cli/build/index.js:665:9)

Additional context

This is a regression traced to #16411.

Issue can be addressed with the following package patch (targeting jest-config):

diff --git a/build/index.js b/build/index.js
index ba4be77..5fb14d9 100644
--- a/build/index.js
+++ b/build/index.js
@@ -1243,7 +1243,11 @@ async function readConfigs(argv, projectPaths) {
       const parentConfigDirname = configPath ? path().dirname(configPath) : cwd;
       // The config that supplies the global config must not be validated
       // as a project config - its global options are in the right place.
-      const suppliesGlobalConfig = globalConfig == null && projectIndex === 0 || configPath != null && typeof root === 'string' && (0, _resolveConfigPath.default)(root, cwd, projectIsCwd) === configPath;
+      const suppliesGlobalConfig = !skipArgvConfigOption || globalConfig == null && projectIndex === 0 || configPath != null && typeof root === 'string' && (0, _resolveConfigPath.default)(root, cwd, projectIsCwd) === configPath;
       return readConfig(argv, root, skipArgvConfigOption, parentConfigDirname, projectIndex,
       // we wanna skip the warning if this is the "main" project
       projectIsCwd, skipArgvConfigOption && !suppliesGlobalConfig);

Or worked around by ensuring a package.json exists at or above cwd.

Environment

System:
    OS: Linux 6.8 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (16) x64 Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz
  Binaries:
    Node: 24.12.0 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 11.6.2 - /usr/bin/npm
    pnpm: 12.5.1 - /home/coder/.local/bin/pnpm

Activity

  1. github-actions commented on Oct 23, 2026

    @github-actions

    This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

  2. Silic0nS0ldier commented on Oct 23, 2026

    @Silic0nS0ldier
    Author

    Not stale

  3. added a commit that references this issue on Nov 9, 2026
    75e9c0b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions