react-idle-timer: After installing Latest version of React-idle-timeout getting compilation error

I’m not using React CRA in my project . Current version npm i react-idle-timer@5.0.0-rc.12 --save getting below error

"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-router-dom": "^5.1.2",

image

Please let me know how to fix this issue as I need to add multi tab session extension feature over my project. With react-idle-timer@4.6.4 The ideal event is not getting triggered for multiple tabs even if I provide

  const idleMethods = useIdleTimer({
        timeout:timeoutValue,
        onIdle:(e) => _onIdle(e),
        crossTab: true,
        emitOnAllTabs: true,
        onActive:_onActive,
        onAction:_onAction,
        startOnMount:true
  })

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 47 (27 by maintainers)

Most upvoted comments

Thanks! Works great now.

Okay noted. If you could take the time to recreate the issue in a stack blitz, I can work on fixing it. We will def want to resolve this before releasing v5 to GA.

It actually might be related to the name of the file. Can you try to change it in your local node_modules. index.esm.js to index.js and update it in the package.json as well?

@SupremeTechnopriest This is how I’m using while running my app like npm run dev that time I’m getting this issue

ERROR in ./node_modules/react-idle-timer/dist/index.esm.js 1:12325
Module parse failed: Unexpected token (1:12325)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> var $e=Object.create,pe=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var Qe=Object.getOwnPropertyNames;var Ze=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var tt=t=>pe(t,"__esModule",{value:!0});var rt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var nt=(t,e,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Qe(e))!et.call(t,r)&&r!=="default"&&pe(t,r,{get:()=>e[r],enumerable:!(n=Ke(e,r))||n.enumerable});return t},ot=t=>nt(tt(pe(t!=null?$e(Ze(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var Me=rt((ne,Le)=>{(function(t,e){typeof ne=="object"&&typeof Le!="undefined"?e(ne):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t.fastUniqueNumbers={}))})(ne,function(t){"use strict";var e=function(o){return function(p){var d=o(p);return p.add(d),d}},n=function(o){return function(p,d){return o.set(p,d),d}},r=Number.MAX_SAFE_INTEGER===void 0?9007199254740991:Number.MAX_SAFE_INTEGER,i=536870912,h=i*2,b=function(o,p){return function(d){var W=p.get(d),M=W===void 0?d.size:W<h?W+1:0;if(!d.has(M))return o(d,M);if(d.size<i){for(;d.has(M);)M=Math.floor(Math.random()*h);return o(d,M)}if(d.size>r)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;d.has(M);)M=Math.floor(Math.random()*r);return o(d,M)}},y=new WeakMap,L=n(y),m=b(L,y),a=e(m);t.addUniqueNumber=a,t.generateUniqueNumber=m,Object.defineProperty(t,"__esModule",{value:!0})})});function st(t){return function(n){let r={...n};!r.onPrompt&&t.prototype.onPrompt&&(r.onPrompt=()=>{t.prototype.onPrompt()}),!r.onIdle&&t.prototype.onIdle&&(r.onIdle=()=>{t.prototype.onIdle()}),!r.onActive&&t.prototype.onActive&&(r.onActive=h=>{t.prototype.onActive(h)}),!r.onAction&&t.prototype.onAction&&(r.onAction=h=>{t.prototype.onAction(h)});let i=X(r);return React.createElement(t,{...n,...i})}}import{useEffect as B,useRef as f,useCallback as I}from"react";var $=ot(Me());var ke=t=>t.method!==void 0&&t.method==="call";var xe=t=>t.error===null&&typeof t.id=="number";var Se=t=>{let e=new Map([[0,()=>{}]]),n=new Map([[0,()=>{}]]),r=new Map,i=new Worker(t);return i.addEventListener("message",({data:m})=>{if(ke(m)){let{params:{timerId:a,timerType:c}}=m;if(c==="interval"){let o=e.get(a);if(typeof o=="number"){let p=r.get(o);if(p===void 0||p.timerId!==a||p.timerType!==c)throw new Error("The timer is in an undefined state.")}else if(typeof o!="undefined")o();else throw new Error("The timer is in an undefined state.")}else if(c==="timeout"){let o=n.get(a);if(typeof o=="number"){let p=r.get(o);if(p===void 0||p.timerId!==a||p.timerType!==c)throw new Error("The timer is in an undefined state.")}else if(typeof o!="undefined")o(),n.delete(a);else throw new Error("The timer is in an undefined state.")}}else if(xe(m)){let{id:a}=m,c=r.get(a);if(c===void 0)throw new Error("The timer is in an undefined state.");let{timerId:o,timerType:p}=c;r.delete(a),p==="interval"?e.delete(o):n.delete(o)}else{let{error:{message:a}}=m;throw new Error(a)}}),{clearInterval:m=>{let a=(0,$.generateUniqueNumber)(r);r.set(a,{timerId:m,timerType:"interval"}),e.set(m,a),i.postMessage({id:a,method:"clear",params:{timerId:m,timerType:"interval"}})},clearTimeout:m=>{let a=(0,$.generateUniqueNumber)(r);r.set(a,{timerId:m,timerType:"timeout"}),n.set(m,a),i.postMessage({id:a,method:"clear",params:{timerId:m,timerType:"timeout"}})},setInterval:(m,a)=>{let c=(0,$.generateUniqueNumber)(e);return e.set(c,()=>{m(),typeof e.get(c)=="function"&&i.postMessage({id:null,method:"set",params:{delay:a,now:performance.now(),timerId:c,timerType:"interval"}})}),i.postMessage({id:null,method:"set",params:{delay:a,now:performance.now(),timerId:c,timerType:"interval"}}),c},setTimeout:(m,a)=>{let c=(0,$.generateUniqueNumber)(n);return n.set(c,m),i.postMessage({id:null,method:"set",params:{delay:a,now:performance.now(),timerId:c,timerType:"timeout"}}),c}}};var K=null,Re=(t,e)=>()=>{if(K!==null)return K;let n=new Blob([e],{type:"application/javascript; charset=utf-8"}),r=URL.createObjectURL(n);return K=t(r),K.setTimeout(()=>URL.revokeObjectURL(r),0),K};var Pe=`(()=>{"use strict";const e=new Map,t=new Map,r=(e,t)=>{let r,o;const i=performance.now();r=i,o=e-Math.max(0,i-t);return{expected:r+o,remainingDelay:o}},o=(e,t,r,i)=>{const s=performance.now();s>r?postMessage({id:null,method:"call",params:{timerId:t,timerType:i}}):e.set(t,setTimeout(o,r-s,e,t,r,i))};addEventListener("message",(i=>{let{data:s}=i;try{if("clear"===s.method){const{id:r,params:{timerId:o,timerType:i}}=s;if("interval"===i)(t=>{const r=e.get(t);if(void 0===r)throw new Error('There is no interval scheduled with the given id "'.concat(t,'".'));clearTimeout(r),e.delete(t)})(o),postMessage({error:null,id:r});else{if("timeout"!==i)throw new Error('The given type "'.concat(i,'" is not supported'));(e=>{const r=t.get(e);if(void 0===r)throw new Error('There is no timeout scheduled with the given id "'.concat(e,'".'));clearTimeout(r),t.delete(e)})(o),postMessage({error:null,id:r})}}else{if("set"!==s.method)throw new Error('The given method "'.concat(s.method,'" is not supported'));{const{params:{delay:i,now:n,timerId:a,timerType:d}}=s;if("interval"===d)((t,i,s)=>{const{expected:n,remainingDelay:a}=r(t,s);e.set(i,setTimeout(o,a,e,i,n,"interval"))})(i,a,n);else{if("timeout"!==d)throw new Error('The given type "'.concat(d,'" is not supported'));((e,i,s)=>{const{expected:n,remainingDelay:a}=r(e,s);t.set(i,setTimeout(o,a,t,i,n,"timeout"))})(i,a,n)}}}}catch(e){postMessage({error:{message:e.message},id:s.id,result:null})}}))})();`;var oe=Re(Se,Pe),fe=t=>oe().clearInterval(t),Ae=t=>oe().clearTimeout(t),De=(t,e)=>oe().setInterval(t,e),G=(t,e)=>oe().setTimeout(t,e);var q={},_e=class{constructor(e){this.closed=!1;this.mc=new MessageChannel;this.name=e,q[e]=q[e]||[],q[e].push(this),this.mc.port1.start(),this.mc.port2.start(),this.onStorage=this.onStorage.bind(this),window.addEventListener("storage",this.onStorage)}onStorage(e){if(e.storageArea!==window.localStorage||e.key.substring(0,this.name.length)!==this.name||e.newValue===null)return;let n=JSON.parse(e.newValue);this.mc.port2.postMessage(n)}postMessage(e){if(this.closed)throw new Error("InvalidStateError");let n=JSON.stringify(e),r=`${this.name}:${String(Date.now())}${String(Math.random())}`;window.localStorage.setItem(r,n),G(()=>{window.localStorage.removeItem(r)},500),q[this.name].forEach(i=>{i!==this&&i.mc.port2.postMessage(JSON.parse(n))})}close(){if(this.closed)return;this.closed=!0,this.mc.port1.close(),this.mc.port2.close(),window.removeEventListener("storage",this.onStorage);let e=q[this.name].indexOf(this);q[this.name].splice(e,1)}get onmessage(){return this.mc.port1.onmessage}set onmessage(e){this.mc.port1.onmessage=e}get onmessageerror(){return this.mc.port1.onmessageerror}set onmessageerror(e){this.mc.port1.onmessageerror=e}addEventListener(e,n){return this.mc.port1.addEventListener(e,n)}removeEventListener(e,n){return this.mc.port1.removeEventListener(e,n)}dispatchEvent(e){return this.mc.port1.dispatchEvent(e)}},Ce=typeof window=="undefined"?void 0:typeof window.BroadcastChannel=="function"?window.BroadcastChannel:_e;function Oe(t=0){return new Promise(e=>G(e,t))}var U=(typeof window=="undefined"?"undefined":typeof window)=="object";var E=()=>U?performance.now():Date.now();function Ne(){return E().toString(36).substring(2)}var V;(function(e){e[e.LEADER=0]="LEADER"})(V||(V={}));var k;(function(r){r[r.APPLY=0]="APPLY",r[r.TELL=1]="TELL",r[r.CLOSE=2]="CLOSE"})(k||(k={}));var he=class{constructor(e,n){this.token=Ne();this.isLeader=!1;this.isDead=!1;this.isApplying=!1;this.intervals=[];this.listeners=[];this.channel=e,this.options=n,this.apply=this.apply.bind(this),this.awaitLeadership=this.awaitLeadership.bind(this),this.sendAction=this.sendAction.bind(this)}async apply(){if(this.isLeader||this.isDead||this.isApplying)return!1;this.isApplying=!0;let e=!1,n=r=>{let{ctx:i,token:h,action:b}=r.data;i===0&&h!==this.token&&(b===0&&h>this.token&&(e=!0),b===1&&(e=!0))};this.channel.addEventListener("message",n);try{if(this.sendAction(0),await Oe(this.options.responseTime),e)throw new Error;return this.sendAction(0),this.assumeLead(),this.channel.removeEventListener("message",n),this.isApplying=!1,!0}catch{return!1}}awaitLeadership(){if(this.isLeader)return Promise.resolve();let e=!1,n=null;return new Promise(r=>{let i=()=>{if(e)return;e=!0,fe(n);let b=this.intervals.indexOf(n);this.intervals.splice(b,1),this.channel.removeEventListener("message",h),r()};n=De(()=>{this.apply().then(()=>{this.isLeader&&i()})},this.options.fallbackInterval),this.intervals.push(n);let h=b=>{let{ctx:y,action:L}=b.data;y===0&&L===2&&this.apply().then(()=>{this.isLeader&&i()})};this.channel.addEventListener("message",h)})}sendAction(e){this.channel.postMessage({ctx:0,action:e,token:this.token})}assumeLead(){this.isLeader=!0;let e=n=>{let{ctx:r,action:i}=n.data;r===0&&i===0&&this.sendAction(1)};return this.channel.addEventListener("message",e),this.listeners.push(e),this.sendAction(1)}waitForLeadership(){return this.deferred?this.deferred:(this.deferred=this.awaitLeadership(),this.deferred)}close(){this.isDead||(this.isDead=!0,this.isLeader=!1,this.sendAction(2),this.listeners.forEach(e=>this.channel.removeEventListener("message",e)),this.intervals.forEach(e=>fe(e)))}};var l;(function(o){o[o.REGISTER=0]="REGISTER",o[o.DEREGISTER=1]="DEREGISTER",o[o.IDLE=2]="IDLE",o[o.ACTIVE=3]="ACTIVE",o[o.EMIT_IDLE=4]="EMIT_IDLE",o[o.EMIT_ACTIVE=5]="EMIT_ACTIVE",o[o.EMIT_MESSAGE=6]="EMIT_MESSAGE",o[o.START=7]="START",o[o.RESET=8]="RESET",o[o.PAUSE=9]="PAUSE",o[o.RESUME=10]="RESUME",o[o.MESSAGE=11]="MESSAGE"})(l||(l={}));var Te=class{constructor(e){this.isLeader=!1;this.allIdle=!1;this.registry=new Map;let{channelName:n,fallbackInterval:r,responseTime:i}=e;this.options=e,this.channel=new Ce(n),this.elector=new he(this.channel,{fallbackInterval:r,responseTime:i}),this.elector.waitForLeadership().then(()=>{this.isLeader=!0}),this.channel.addEventListener("message",h=>{let{action:b,token:y,data:L}=h.data;switch(b){case 0:this.registry.set(y,!1);break;case 1:this.registry.delete(y);break;case 2:this.idle(y);break;case 3:this.active(y);break;case 4:this.options.onIdle();break;case 5:this.options.onActive();break;case 6:this.options.onMessage(L);break;case 7:this.options.start(!0);break;case 8:this.options.reset(!0);break;case 9:this.options.pause(!0);break;case 10:this.options.resume(!0);break}}),this.send(0)}idle(e=this.elector.token){this.registry.set(e,!0);let n=[...this.registry.values()].every(r=>r);!this.allIdle&&n&&(this.allIdle=!0,this.isLeader?(this.options.onIdle(),this.options.emitOnAllTabs&&this.send(4)):this.send(2))}active(e=this.elector.token){this.registry.set(e,!1);let n=[...this.registry.values()].some(r=>!r);this.allIdle&&n&&(this.allIdle=!1,this.isLeader?(this.options.onActive(),this.options.emitOnAllTabs&&this.send(5)):this.send(3))}message(e){try{this.channel.postMessage({action:6,token:this.elector.token,data:e})}catch{}}send(e){try{this.channel.postMessage({action:e,token:this.elector.token})}catch{}}close(){this.send(1),this.elector.close(),this.channel.close()}};var Fe=U?document:null,Ue=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange"];import{useRef as it,useEffect as at}from"react";function N(t){let e=it(t);return at(()=>{e.current=t},[t]),e}function Be(t,e){let n;function r(...i){n&&clearTimeout(n),n=setTimeout(()=>{t(...i),n=null},e)}return r.cancel=function(){clearTimeout(n)},r}function ve(t,e){let n=0;return function(...r){let i=new Date().getTime();if(!(i-n<e))return 
n=i,t(...r)}}function X({timeout:t=1e3*60*20,promptTimeout:e=0,element:n=Fe,events:r=Ue,immediateEvents:i=[],onPrompt:h=()=>{},onIdle:b=()=>{},onActive:y=()=>{},onAction:L=()=>{},onMessage:m=()=>{},debounce:a=0,throttle:c=0,eventsThrottle:o=200,startOnMount:p=!0,startManually:d=!1,stopOnIdle:W=!1,crossTab:M=!1,emitOnAllTabs:x=!1}={}){let j=f(E()),Ee=f(Date.now()),R=f(null),P=f(null),Y=f(0),T=f(!0),S=f(!1),Q=f(!0),z=f(!1),g=f(!1),w=f(0),A=f(0),D=f(null),u=f(null),ie=N(e),We=N(W),He=N(i),ae=f(r),ue=f(n),ce=N(b),Z=N(y),Ge=N(h),ee=N(m),_=f();B(()=>{_.current?.cancel&&_.current.cancel(),a>0?_.current=Be(L,a):c>0?_.current=ve(L,c):_.current=L},[L,c,a]);let C=()=>{D.current!==null&&(Ae(D.current),D.current=null)},J=(s,v=!0)=>{C(),D.current=G(le,s||t),v&&(P.current=E())},le=s=>{let v=!T.current;if(v){if(ie.current>0&&!g.current){F(),w.current=0,A.current=E(),g.current=!0,Ge.current(s),J(ie.current,!1);return}T.current=v,We.current?(C(),F()):g.current&&(O(),A.current=0,g.current=!1),R.current=E(),u.current?u.current.idle():ce.current();return}T.current=v,Y.current+=E()-R.current,O(),u.current?u.current.active():Z.current(s)},Ie=s=>{_.current(s),C();let v=E()-P.current;if((T.current&&!W||!T.current&&v>t)&&le(s),S.current=!1,w.current=0,A.current=0,!T.current&&He.current.includes(s.type)){le(s);return}J()},te=f();B(()=>{let s=z.current;s&&F(),o>0?te.current=ve(Ie,o):te.current=Ie,s&&O()},[o]);let O=()=>{!U||z.current||(ae.current.forEach(s=>{ue.current.addEventListener(s,te.current,{capture:!0,passive:!0})}),z.current=!0)},F=(s=!1)=>{!U||(z.current||s)&&(ae.current.forEach(v=>{ue.current.removeEventListener(v,te.current,{capture:!0})}),z.current=!1)},H=I(s=>{C(),O(),T.current=!1,g.current=!1,S.current=!1,w.current=0,A.current=0,u.current&&(u.current.allIdle=!1,!s&&x&&u.current.send(l.START)),J()},[D,T,t,n,r,x]),re=I(s=>{C(),O(),(T.current||g.current)&&(u.current?u.current.active():Z.current()),T.current=!1,g.current=!1,S.current=!1,w.current=0,A.current=0,u.current&&(u.current.allIdle=!1,!s&&x&&u.current.send(l.RESET)),J()},[D,T,t,n,r,x]),me=I((s=!1)=>S.current?!1:(w.current=be(),S.current=!0,F(),C(),u.current&&!s&&x&&u.current.send(l.PAUSE),!0),[D,n,r,x,u]),de=I((s=!1)=>S.current?(S.current=!1,g.current||O(),T.current||J(w.current),A.current&&(A.current=E()),u.current&&!s&&x&&u.current.send(l.RESUME),!0):!1,[D,w,n,r,x,u]),qe=I((s,v)=>{u.current?(v&&ee.current(s),u.current.message(s)):v&&ee.current(s)},[m]),Ve=I(()=>T.current,[T]),je=I(()=>g.current,[g]),Ye=I(()=>u.current?u.current.isLeader:!0,[u]),be=I(()=>{if(S.current)return w.current;let s=w.current?w.current:g.current?ie.current:t,v=P.current?g.current?E()-A.current:E()-P.current:0,we=Math.ceil(s-v);return we<0?0:Math.abs(we)},[t,e,g,w,P]),ge=I(()=>Math.round(E()-j.current),[j]),ze=I(()=>R.current?new Date(Ee.current-j.current+R.current):null,[R]),Je=I(()=>P.current?new Date(Ee.current-j.current+P.current):null,[P]),ye=I(()=>T.current?Math.round(E()-R.current+Y.current):Math.round(Y.current),[R,Y]),Xe=I(()=>{let s=Math.round(ge()-ye());return s>=0?s:0},[j,R,Y]);return B(()=>{if(a>0&&c>0)throw new Error("\u274C onAction can either be throttled or debounced, not both.");return()=>{C(),F(!0),_.current.cancel&&_.current.cancel(),u.current&&u.current.close()}},[]),B(()=>{if(!Q.current){if(F(),ae.current=r,ue.current=n,d)return;p?H():O()}},[r,n]),B(()=>{C(),F(!0),Q.current||(S.current=!0,T.current=!0,w.current=0),!d&&(p?H():O())},[d,p]),B(()=>{if(Q.current)Q.current=!1;else if(T.current){if(d)return;re()}else H()},[t]),B(()=>{u.current&&u.current.close(),M?u.current=new Te({channelName:"idle-timer",fallbackInterval:2e3,responseTime:100,emitOnAllTabs:x,onIdle:ce.current,onActive:Z.current,onMessage:ee.current,start:H,reset:re,pause:me,resume:de}):u.current=null},[M,x,ce,Z,ee,H,re,me,de]),{message:qe,start:H,reset:re,pause:me,resume:de,isIdle:Ve,isPrompted:je,isLeader:Ye,getRemainingTime:be,getElapsedTime:ge,getLastIdleTime:ze,getLastActiveTime:Je,getTotalIdleTime:ye,getTotalActiveTime:Xe}}import{createContext as ut,useContext as ct}from"react";var se=ut(null);function lt(t){let e=X(t);return React.createElement(se.Provider,{value:e},t.children)}var mt=se.Consumer;function dt(){return ct(se)}export{mt as IdleTimerConsumer,se as IdleTimerContext,lt as IdleTimerProvider,X as useIdleTimer,dt as useIdleTimerContext,st as withIdleTimer};
| //# sourceMappingURL=index.esm.js.map
import React, { Fragment, useState, useEffect } from 'react';
import intl from 'react-intl-universal';
import { useIdleTimer } from 'react-idle-timer';

test: /\.(js|jsx)$/, this looks like it should match just fine. Its something with the optional chaining.

Can you also try updating babel/core to the latest. Worst case scenario I can compile the optional chaining out of the library, but it is widely supported now and would result in a larger package.

Can you try updating babel-preset-env to the latest 7.16.11

ERROR in ./node_modules/react-idle-timer/dist/index.esm.js 1:12325
Module parse failed: Unexpected token (1:12325)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> var $e=Object.create,pe=Object.defineProperty;var Ke=Object.getOwnPropertyDescriptor;var Qe=Object.getOwnPropertyNames;var Ze=Object.getPrototypeOf,et=Object.prototype.hasOwnProperty;var tt=t=>pe(t,"__esModule",{value:!0});var rt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var nt=(t,e,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Qe(e))!et.call(t,r)&&r!=="default"&&pe(t,r,{get:()=>e[r],enumerable:!(n=Ke(e,r))||n.enumerable});return t},ot=t=>nt(tt(pe(t!=null?$e(Ze(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);var Me=rt((ne,Le)=>{(function(t,e){typeof ne=="object"&&typeof Le!="undefined"?e(ne):typeof define=="function"&&define.amd?define(["exports"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t.fastUniqueNumbers={}))})(ne,function(t){"use strict";var e=function(o){return function(p){var d=o(p);return p.add(d),d}},n=function(o){return function(p,d){return o.set(p,d),d}},r=Number.MAX_SAFE_INTEGER===void 0?9007199254740991:Number.MAX_SAFE_INTEGER,i=536870912,h=i*2,b=function(o,p){return function(d){var W=p.get(d),M=W===void 0?d.size:W<h?W+1:0;if(!d.has(M))return o(d,M);if(d.size<i){for(;d.has(M);)M=Math.floor(Math.random()*h);return o(d,M)}if(d.size>r)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;d.has(M);)M=Math.floor(Math.random()*r);return o(d,M)}},y=new WeakMap,L=n(y),m=b(L,y),a=e(m);t.addUniqueNumber=a,t.generateUniqueNumber=m,Object.defineProperty(t,"__esModule",{value:!0})})});function st(t){return function(n){let r={...n};!r.onPrompt&&t.prototype.onPrompt&&(r.onPrompt=()=>{t.prototype.onPrompt()}),!r.onIdle&&t.prototype.onIdle&&(r.onIdle=()=>{t.prototype.onIdle()}),!r.onActive&&t.prototype.onActive&&(r.onActive=h=>{t.prototype.onActive(h)}),!r.onAction&&t.prototype.onAction&&(r.onAction=h=>{t.prototype.onAction(h)});let i=X(r);return React.createElement(t,{...n,...i})}}import{useEffect as B,useRef as f,useCallback as I}from"react";var $=ot(Me());var ke=t=>t.method!==void 0&&t.method==="call";var xe=t=>t.error===null&&typeof t.id=="number";var Se=t=>{let e=new Map([[0,()=>{}]]),n=new Map([[0,()=>{}]]),r=new Map,i=new Worker(t);return i.addEventListener("message",({data:m})=>{if(ke(m)){let{params:{timerId:a,timerType:c}}=m;if(c==="interval"){let o=e.get(a);if(typeof o=="number"){let p=r.get(o);if(p===void 0||p.timerId!==a||p.timerType!==c)throw new Error("The timer is in an undefined state.")}else if(typeof o!="undefined")o();else throw new Error("The timer is in an undefined state.")}else if(c==="timeout"){let o=n.get(a);if(typeof o=="number"){let p=r.get(o);if(p===void 0||p.timerId!==a||p.timerType!==c)throw new Error("The timer is in an undefined state.")}else if(typeof o!="undefined")o(),n.delete(a);else throw new Error("The timer is in an undefined state.")}}else if(xe(m)){let{id:a}=m,c=r.get(a);if(c===void 0)throw new Error("The timer is in an undefined state.");let{timerId:o,timerType:p}=c;r.delete(a),p==="interval"?e.delete(o):n.delete(o)}else{let{error:{message:a}}=m;throw new Error(a)}}),{clearInterval:m=>{let a=(0,$.generateUniqueNumber)(r);r.set(a,{timerId:m,timerType:"interval"}),e.set(m,a),i.postMessage({id:a,method:"clear",params:{timerId:m,timerType:"interval"}})},clearTimeout:m=>{let a=(0,$.generateUniqueNumber)(r);r.set(a,{timerId:m,timerType:"timeout"}),n.set(m,a),i.postMessage({id:a,method:"clear",params:{timerId:m,timerType:"timeout"}})},setInterval:(m,a)=>{let c=(0,$.generateUniqueNumber)(e);return e.set(c,()=>{m(),typeof e.get(c)=="function"&&i.postMessage({id:null,method:"set",params:{delay:a,now:performance.now(),timerId:c,timerType:"interval"}})}),i.postMessage({id:null,method:"set",params:{delay:a,now:performance.now(),timerId:c,timerType:"interval"}}),c},setTimeout:(m,a)=>{let c=(0,$.generateUniqueNumber)(n);return n.set(c,m),i.postMessage({id:null,method:"set",params:{delay:a,now:performance.now(),timerId:c,timerType:"timeout"}}),c}}};var K=null,Re=(t,e)=>()=>{if(K!==null)return K;let n=new Blob([e],{type:"application/javascript; charset=utf-8"}),r=URL.createObjectURL(n);return K=t(r),K.setTimeout(()=>URL.revokeObjectURL(r),0),K};var Pe=`(()=>{"use strict";const e=new Map,t=new Map,r=(e,t)=>{let r,o;const i=performance.now();r=i,o=e-Math.max(0,i-t);return{expected:r+o,remainingDelay:o}},o=(e,t,r,i)=>{const s=performance.now();s>r?postMessage({id:null,method:"call",params:{timerId:t,timerType:i}}):e.set(t,setTimeout(o,r-s,e,t,r,i))};addEventListener("message",(i=>{let{data:s}=i;try{if("clear"===s.method){const{id:r,params:{timerId:o,timerType:i}}=s;if("interval"===i)(t=>{const r=e.get(t);if(void 0===r)throw new Error('There is no interval scheduled with the given id "'.concat(t,'".'));clearTimeout(r),e.delete(t)})(o),postMessage({error:null,id:r});else{if("timeout"!==i)throw new Error('The given type "'.concat(i,'" is not supported'));(e=>{const r=t.get(e);if(void 0===r)throw new Error('There is no timeout scheduled with the given id "'.concat(e,'".'));clearTimeout(r),t.delete(e)})(o),postMessage({error:null,id:r})}}else{if("set"!==s.method)throw new Error('The given method "'.concat(s.method,'" is not supported'));{const{params:{delay:i,now:n,timerId:a,timerType:d}}=s;if("interval"===d)((t,i,s)=>{const{expected:n,remainingDelay:a}=r(t,s);e.set(i,setTimeout(o,a,e,i,n,"interval"))})(i,a,n);else{if("timeout"!==d)throw new Error('The given type "'.concat(d,'" is not supported'));((e,i,s)=>{const{expected:n,remainingDelay:a}=r(e,s);t.set(i,setTimeout(o,a,t,i,n,"timeout"))})(i,a,n)}}}}catch(e){postMessage({error:{message:e.message},id:s.id,result:null})}}))})();`;var oe=Re(Se,Pe),fe=t=>oe().clearInterval(t),Ae=t=>oe().clearTimeout(t),De=(t,e)=>oe().setInterval(t,e),G=(t,e)=>oe().setTimeout(t,e);var q={},_e=class{constructor(e){this.closed=!1;this.mc=new MessageChannel;this.name=e,q[e]=q[e]||[],q[e].push(this),this.mc.port1.start(),this.mc.port2.start(),this.onStorage=this.onStorage.bind(this),window.addEventListener("storage",this.onStorage)}onStorage(e){if(e.storageArea!==window.localStorage||e.key.substring(0,this.name.length)!==this.name||e.newValue===null)return;let n=JSON.parse(e.newValue);this.mc.port2.postMessage(n)}postMessage(e){if(this.closed)throw new Error("InvalidStateError");let n=JSON.stringify(e),r=`${this.name}:${String(Date.now())}${String(Math.random())}`;window.localStorage.setItem(r,n),G(()=>{window.localStorage.removeItem(r)},500),q[this.name].forEach(i=>{i!==this&&i.mc.port2.postMessage(JSON.parse(n))})}close(){if(this.closed)return;this.closed=!0,this.mc.port1.close(),this.mc.port2.close(),window.removeEventListener("storage",this.onStorage);let e=q[this.name].indexOf(this);q[this.name].splice(e,1)}get onmessage(){return this.mc.port1.onmessage}set onmessage(e){this.mc.port1.onmessage=e}get onmessageerror(){return this.mc.port1.onmessageerror}set onmessageerror(e){this.mc.port1.onmessageerror=e}addEventListener(e,n){return this.mc.port1.addEventListener(e,n)}removeEventListener(e,n){return this.mc.port1.removeEventListener(e,n)}dispatchEvent(e){return this.mc.port1.dispatchEvent(e)}},Ce=typeof window=="undefined"?void 0:typeof window.BroadcastChannel=="function"?window.BroadcastChannel:_e;function Oe(t=0){return new Promise(e=>G(e,t))}var U=(typeof window=="undefined"?"undefined":typeof window)=="object";var E=()=>U?performance.now():Date.now();function Ne(){return E().toString(36).substring(2)}var V;(function(e){e[e.LEADER=0]="LEADER"})(V||(V={}));var k;(function(r){r[r.APPLY=0]="APPLY",r[r.TELL=1]="TELL",r[r.CLOSE=2]="CLOSE"})(k||(k={}));var he=class{constructor(e,n){this.token=Ne();this.isLeader=!1;this.isDead=!1;this.isApplying=!1;this.intervals=[];this.listeners=[];this.channel=e,this.options=n,this.apply=this.apply.bind(this),this.awaitLeadership=this.awaitLeadership.bind(this),this.sendAction=this.sendAction.bind(this)}async apply(){if(this.isLeader||this.isDead||this.isApplying)return!1;this.isApplying=!0;let e=!1,n=r=>{let{ctx:i,token:h,action:b}=r.data;i===0&&h!==this.token&&(b===0&&h>this.token&&(e=!0),b===1&&(e=!0))};this.channel.addEventListener("message",n);try{if(this.sendAction(0),await Oe(this.options.responseTime),e)throw new Error;return this.sendAction(0),this.assumeLead(),this.channel.removeEventListener("message",n),this.isApplying=!1,!0}catch{return!1}}awaitLeadership(){if(this.isLeader)return Promise.resolve();let e=!1,n=null;return new Promise(r=>{let i=()=>{if(e)return;e=!0,fe(n);let b=this.intervals.indexOf(n);this.intervals.splice(b,1),this.channel.removeEventListener("message",h),r()};n=De(()=>{this.apply().then(()=>{this.isLeader&&i()})},this.options.fallbackInterval),this.intervals.push(n);let h=b=>{let{ctx:y,action:L}=b.data;y===0&&L===2&&this.apply().then(()=>{this.isLeader&&i()})};this.channel.addEventListener("message",h)})}sendAction(e){this.channel.postMessage({ctx:0,action:e,token:this.token})}assumeLead(){this.isLeader=!0;let e=n=>{let{ctx:r,action:i}=n.data;r===0&&i===0&&this.sendAction(1)};return this.channel.addEventListener("message",e),this.listeners.push(e),this.sendAction(1)}waitForLeadership(){return this.deferred?this.deferred:(this.deferred=this.awaitLeadership(),this.deferred)}close(){this.isDead||(this.isDead=!0,this.isLeader=!1,this.sendAction(2),this.listeners.forEach(e=>this.channel.removeEventListener("message",e)),this.intervals.forEach(e=>fe(e)))}};var l;(function(o){o[o.REGISTER=0]="REGISTER",o[o.DEREGISTER=1]="DEREGISTER",o[o.IDLE=2]="IDLE",o[o.ACTIVE=3]="ACTIVE",o[o.EMIT_IDLE=4]="EMIT_IDLE",o[o.EMIT_ACTIVE=5]="EMIT_ACTIVE",o[o.EMIT_MESSAGE=6]="EMIT_MESSAGE",o[o.START=7]="START",o[o.RESET=8]="RESET",o[o.PAUSE=9]="PAUSE",o[o.RESUME=10]="RESUME",o[o.MESSAGE=11]="MESSAGE"})(l||(l={}));var Te=class{constructor(e){this.isLeader=!1;this.allIdle=!1;this.registry=new Map;let{channelName:n,fallbackInterval:r,responseTime:i}=e;this.options=e,this.channel=new Ce(n),this.elector=new he(this.channel,{fallbackInterval:r,responseTime:i}),this.elector.waitForLeadership().then(()=>{this.isLeader=!0}),this.channel.addEventListener("message",h=>{let{action:b,token:y,data:L}=h.data;switch(b){case 0:this.registry.set(y,!1);break;case 1:this.registry.delete(y);break;case 2:this.idle(y);break;case 3:this.active(y);break;case 4:this.options.onIdle();break;case 5:this.options.onActive();break;case 6:this.options.onMessage(L);break;case 7:this.options.start(!0);break;case 8:this.options.reset(!0);break;case 9:this.options.pause(!0);break;case 10:this.options.resume(!0);break}}),this.send(0)}idle(e=this.elector.token){this.registry.set(e,!0);let n=[...this.registry.values()].every(r=>r);!this.allIdle&&n&&(this.allIdle=!0,this.isLeader?(this.options.onIdle(),this.options.emitOnAllTabs&&this.send(4)):this.send(2))}active(e=this.elector.token){this.registry.set(e,!1);let n=[...this.registry.values()].some(r=>!r);this.allIdle&&n&&(this.allIdle=!1,this.isLeader?(this.options.onActive(),this.options.emitOnAllTabs&&this.send(5)):this.send(3))}message(e){try{this.channel.postMessage({action:6,token:this.elector.token,data:e})}catch{}}send(e){try{this.channel.postMessage({action:e,token:this.elector.token})}catch{}}close(){this.send(1),this.elector.close(),this.channel.close()}};var Fe=U?document:null,Ue=["mousemove","keydown","wheel","DOMMouseScroll","mousewheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove","visibilitychange"];import{useRef as it,useEffect as at}from"react";function N(t){let e=it(t);return at(()=>{e.current=t},[t]),e}function Be(t,e){let n;function r(...i){n&&clearTimeout(n),n=setTimeout(()=>{t(...i),n=null},e)}return r.cancel=function(){clearTimeout(n)},r}function ve(t,e){let n=0;return function(...r){let i=new Date().getTime();if(!(i-n<e))return 
n=i,t(...r)}}function X({timeout:t=1e3*60*20,promptTimeout:e=0,element:n=Fe,events:r=Ue,immediateEvents:i=[],onPrompt:h=()=>{},onIdle:b=()=>{},onActive:y=()=>{},onAction:L=()=>{},onMessage:m=()=>{},debounce:a=0,throttle:c=0,eventsThrottle:o=200,startOnMount:p=!0,startManually:d=!1,stopOnIdle:W=!1,crossTab:M=!1,emitOnAllTabs:x=!1}={}){let j=f(E()),Ee=f(Date.now()),R=f(null),P=f(null),Y=f(0),T=f(!0),S=f(!1),Q=f(!0),z=f(!1),g=f(!1),w=f(0),A=f(0),D=f(null),u=f(null),ie=N(e),We=N(W),He=N(i),ae=f(r),ue=f(n),ce=N(b),Z=N(y),Ge=N(h),ee=N(m),_=f();B(()=>{_.current?.cancel&&_.current.cancel(),a>0?_.current=Be(L,a):c>0?_.current=ve(L,c):_.current=L},[L,c,a]);let C=()=>{D.current!==null&&(Ae(D.current),D.current=null)},J=(s,v=!0)=>{C(),D.current=G(le,s||t),v&&(P.current=E())},le=s=>{let v=!T.current;if(v){if(ie.current>0&&!g.current){F(),w.current=0,A.current=E(),g.current=!0,Ge.current(s),J(ie.current,!1);return}T.current=v,We.current?(C(),F()):g.current&&(O(),A.current=0,g.current=!1),R.current=E(),u.current?u.current.idle():ce.current();return}T.current=v,Y.current+=E()-R.current,O(),u.current?u.current.active():Z.current(s)},Ie=s=>{_.current(s),C();let v=E()-P.current;if((T.current&&!W||!T.current&&v>t)&&le(s),S.current=!1,w.current=0,A.current=0,!T.current&&He.current.includes(s.type)){le(s);return}J()},te=f();B(()=>{let s=z.current;s&&F(),o>0?te.current=ve(Ie,o):te.current=Ie,s&&O()},[o]);let O=()=>{!U||z.current||(ae.current.forEach(s=>{ue.current.addEventListener(s,te.current,{capture:!0,passive:!0})}),z.current=!0)},F=(s=!1)=>{!U||(z.current||s)&&(ae.current.forEach(v=>{ue.current.removeEventListener(v,te.current,{capture:!0})}),z.current=!1)},H=I(s=>{C(),O(),T.current=!1,g.current=!1,S.current=!1,w.current=0,A.current=0,u.current&&(u.current.allIdle=!1,!s&&x&&u.current.send(l.START)),J()},[D,T,t,n,r,x]),re=I(s=>{C(),O(),(T.current||g.current)&&(u.current?u.current.active():Z.current()),T.current=!1,g.current=!1,S.current=!1,w.current=0,A.current=0,u.current&&(u.current.allIdle=!1,!s&&x&&u.current.send(l.RESET)),J()},[D,T,t,n,r,x]),me=I((s=!1)=>S.current?!1:(w.current=be(),S.current=!0,F(),C(),u.current&&!s&&x&&u.current.send(l.PAUSE),!0),[D,n,r,x,u]),de=I((s=!1)=>S.current?(S.current=!1,g.current||O(),T.current||J(w.current),A.current&&(A.current=E()),u.current&&!s&&x&&u.current.send(l.RESUME),!0):!1,[D,w,n,r,x,u]),qe=I((s,v)=>{u.current?(v&&ee.current(s),u.current.message(s)):v&&ee.current(s)},[m]),Ve=I(()=>T.current,[T]),je=I(()=>g.current,[g]),Ye=I(()=>u.current?u.current.isLeader:!0,[u]),be=I(()=>{if(S.current)return w.current;let s=w.current?w.current:g.current?ie.current:t,v=P.current?g.current?E()-A.current:E()-P.current:0,we=Math.ceil(s-v);return we<0?0:Math.abs(we)},[t,e,g,w,P]),ge=I(()=>Math.round(E()-j.current),[j]),ze=I(()=>R.current?new Date(Ee.current-j.current+R.current):null,[R]),Je=I(()=>P.current?new Date(Ee.current-j.current+P.current):null,[P]),ye=I(()=>T.current?Math.round(E()-R.current+Y.current):Math.round(Y.current),[R,Y]),Xe=I(()=>{let s=Math.round(ge()-ye());return s>=0?s:0},[j,R,Y]);return B(()=>{if(a>0&&c>0)throw new Error("\u274C onAction can either be throttled or debounced, not both.");return()=>{C(),F(!0),_.current.cancel&&_.current.cancel(),u.current&&u.current.close()}},[]),B(()=>{if(!Q.current){if(F(),ae.current=r,ue.current=n,d)return;p?H():O()}},[r,n]),B(()=>{C(),F(!0),Q.current||(S.current=!0,T.current=!0,w.current=0),!d&&(p?H():O())},[d,p]),B(()=>{if(Q.current)Q.current=!1;else if(T.current){if(d)return;re()}else H()},[t]),B(()=>{u.current&&u.current.close(),M?u.current=new Te({channelName:"idle-timer",fallbackInterval:2e3,responseTime:100,emitOnAllTabs:x,onIdle:ce.current,onActive:Z.current,onMessage:ee.current,start:H,reset:re,pause:me,resume:de}):u.current=null},[M,x,ce,Z,ee,H,re,me,de]),{message:qe,start:H,reset:re,pause:me,resume:de,isIdle:Ve,isPrompted:je,isLeader:Ye,getRemainingTime:be,getElapsedTime:ge,getLastIdleTime:ze,getLastActiveTime:Je,getTotalIdleTime:ye,getTotalActiveTime:Xe}}import{createContext as ut,useContext as ct}from"react";var se=ut(null);function lt(t){let e=X(t);return React.createElement(se.Provider,{value:e},t.children)}var mt=se.Consumer;function dt(){return ct(se)}export{mt as IdleTimerConsumer,se as IdleTimerContext,lt as IdleTimerProvider,X as useIdleTimer,dt as useIdleTimerContext,st as withIdleTimer};
| //# sourceMappingURL=index.esm.js.map

Could you paste the error as plain text so I can parse it. Trying to find exactly where it’s failing.

Okay give me a little bit to investigate. Will get back to you shortly.