diff --git a/CHANGELOG.md b/CHANGELOG.md index a48e0e91..40de2fa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Changed +- Increase compatibility with external build system such as `rollup` by making perf_hooks optional in gc.js + ### Added ## [14.1.0] - 2022-08-23 diff --git a/lib/metrics/gc.js b/lib/metrics/gc.js index 75b8f4bc..0d2e2839 100644 --- a/lib/metrics/gc.js +++ b/lib/metrics/gc.js @@ -14,10 +14,13 @@ const NODEJS_GC_DURATION_SECONDS = 'nodejs_gc_duration_seconds'; const DEFAULT_GC_DURATION_BUCKETS = [0.001, 0.01, 0.1, 1, 2, 5]; const kinds = []; -kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR] = 'major'; -kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = 'minor'; -kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental'; -kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB] = 'weakcb'; + +if (perf_hooks && perf_hooks.constants) { + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR] = 'major'; + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = 'minor'; + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental'; + kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB] = 'weakcb'; +} module.exports = (registry, config = {}) => { if (!perf_hooks) {