fix: handle unavailable require cache by simPod · Pull Request #20812 · eslint/eslint (original) (raw)

Summary

Root Cause

loadConfigFile() clears require.cache[filePath] before dynamically importing config files so changed CommonJS configs are reloaded consistently with ESM configs. In some loader environments, the require function available to config-loader.js can exist without a cache object. In that case, delete require.cache[filePath] throws before ESLint can load the config.

The failure reproduced as:

TypeError: Cannot convert undefined or null to object
    at loadConfigFile (lib/config/config-loader.js:233:24)

Reproduction Test

The new test loads lib/config/config-loader.js through a VM wrapper using a require created by Module.createRequire(), then sets that wrapper's require.cache to unavailable. Calling ConfigLoader.calculateConfigArray() then exercises the same cache-clearing path without depending on a specific package manager or loader implementation.

Without the fix, the test fails with the require.cache TypeError. With the fix, config loading completes and returns the expected config array.

Backport

This should be backported to v9 because the crash affects ESLint 9.x users in loader environments where require.cache is unavailable.