diff --git a/CHANGELOG.md b/CHANGELOG.md index 60c67811be0f..beaa01e200d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -102,6 +102,7 @@ - `[jest-cli]` print info about passWithNoTests flag ([#7309](https://github.com/facebook/jest/pull/7309)) - `[pretty-format]` Omit unnecessary symbol filter for object keys ([#7457](https://github.com/facebook/jest/pull/7457)) - `[jest-runtime]` Fix `requireActual` on node_modules with mock present ([#7404](https://github.com/facebook/jest/pull/7404)) +- `[jest-resolve]` Fix `isBuiltinModule` to support versions of node without `module.builtinModules` ([#7565](https://github.com/facebook/jest/pull/7565)) ### Chore & Maintenance diff --git a/packages/jest-resolve/src/isBuiltinModule.js b/packages/jest-resolve/src/isBuiltinModule.js index 48378729f34b..69e66e0a0715 100644 --- a/packages/jest-resolve/src/isBuiltinModule.js +++ b/packages/jest-resolve/src/isBuiltinModule.js @@ -17,12 +17,14 @@ declare var process: { const EXPERIMENTAL_MODULES = ['worker_threads']; -const BUILTIN_MODULES = - builtinModules.concat(EXPERIMENTAL_MODULES) || - Object.keys(process.binding('natives')) - .filter((module: string) => !/^internal\//.test(module)) - .concat(EXPERIMENTAL_MODULES); +const BUILTIN_MODULES = new Set( + builtinModules + ? builtinModules.concat(EXPERIMENTAL_MODULES) + : Object.keys(process.binding('natives')) + .filter((module: string) => !/^internal\//.test(module)) + .concat(EXPERIMENTAL_MODULES), +); export default function isBuiltinModule(module: string): boolean { - return BUILTIN_MODULES.indexOf(module) !== -1; + return BUILTIN_MODULES.has(module); }