diff --git a/lib/internal/bootstrap/cache.js b/lib/internal/bootstrap/cache.js index 41fe1e3a914ba0..6181228b033228 100644 --- a/lib/internal/bootstrap/cache.js +++ b/lib/internal/bootstrap/cache.js @@ -6,8 +6,9 @@ // cannot be tampered with even with --expose-internals const { - NativeModule, internalBinding + NativeModule } = require('internal/bootstrap/loaders'); +const { hasTracing } = process.binding('config'); function getCodeCache(id) { const cached = NativeModule.getCached(id); @@ -42,6 +43,16 @@ const cannotUseCache = [ 'internal/bootstrap/node' ].concat(depsModule); +// Skip modules that cannot be required when they are not +// built into the binary. +if (process.config.variables.v8_enable_inspector !== 1) { + cannotUseCache.push('inspector'); + cannotUseCache.push('internal/util/inspector'); +} +if (!hasTracing) { + cannotUseCache.push('trace_events'); +} + module.exports = { cachableBuiltins: Object.keys(NativeModule._source).filter( (key) => !cannotUseCache.includes(key)