nolanlawson / marky

High-resolution JavaScript timer based on performance.mark/measure (491 bytes min+gz)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not work in node 16, `TypeError: perf.getEntriesByName is not a function`

patrickhulce opened this issue · comments

In node 16, performance is a global with the mark method (so the hrtime path isn't used), but it does not have getEntriesByName (so marky.stop throws an exception). Feature detection is now necessary for all the performance methods used :/

if (perf && perf.mark) {

Originally surfaced in GoogleChrome/lighthouse-ci#596

The performance API in Node does not match the performance API for the web as documented on MDN (see https://developer.mozilla.org/en-US/docs/Web/API/Performance/getEntriesByName). Although the Node-specific performance API has been around since Node 10, in Node 16 an instance of this class is now bound to the global variable performance. That's where marky gets confused.

Please consider merging the proposed PR and releasing a patch release. Right now, any software that depends on marky cannot be used on Node 16.