#16457·Jest

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

Author: Silic0nS0ldierCreated Sep 23, 2026Updated Sep 23, 2026
LabelsNeeds TriageBug Report

Version

30.5.1

Steps to reproduce

bash
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
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

bash
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