title: Google Appscript webpacked module not working
body: <p>I'm trying to create some automated scripts using Google AppScript. To help I'm using some npm modules and using Webpack to make them available in GAS. I followed an online tutorial but the script created doesn't work and I'm at a loss. Appscript says Dayjs is undefined so I'm wondering if I messed up when creating the Webpack/minimised version somehow.</p>
  <p>Code.gs:</p>
  <pre><code>
  const testDayjs = () =&gt; console.log (
      dayjs()
      .startOf('month')
      .add(1, 'day')
      .set('year', 2022)
      .format('YYYY-MM-DD HH:mm:ss')
  );
  console.log ('finished', Dayjs)
  </code></pre>
  <p>Day.gs:</p>
  <pre><code>var Dayjs;(()=&gt;{var t={484:function(t){t.exports=function(){&quot;use strict&quot;;var t=6e4,e=36e5,n=&quot;millisecond&quot;,r=&quot;second&quot;,i=&quot;minute&quot;,s=&quot;hour&quot;,u=&quot;day&quot;,a=&quot;week&quot;,o=&quot;month&quot;,f=&quot;quarter&quot;,h=&quot;year&quot;,c=&quot;date&quot;,d=&quot;Invalid Date&quot;,l=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,$=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,y={name:&quot;en&quot;,weekdays:&quot;Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday&quot;.split(&quot;_&quot;),months:&quot;January_February_March_April_May_June_July_August_September_October_November_December&quot;.split(&quot;_&quot;)},v=function(t,e,n){var r=String(t);return!r||r.length&gt;=e?t:&quot;&quot;+Array(e+1-r.length).join(n)+t},M={s:v,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e&lt;=0?&quot;+&quot;:&quot;-&quot;)+v(r,2,&quot;0&quot;)+&quot;:&quot;+v(i,2,&quot;0&quot;)},m:function t(e,n){if(e.date()&lt;n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,o),s=n-i&lt;0,u=e.clone().add(r+(s?-1:1),o);return+(-(r+(n-i)/(s?i-u:u-i))||0)},a:function(t){return t&lt;0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:o,y:h,w:a,d:u,D:c,h:s,m:i,s:r,ms:n,Q:f}[t]||String(t||&quot;&quot;).toLowerCase().replace(/s$/,&quot;&quot;)},u:function(t){return void 0===t}},m=&quot;en&quot;,g={};g[m]=y;var p=function(t){return t instanceof O},D=function t(e,n,r){var i;if(!e)return m;if(&quot;string&quot;==typeof e){var s=e.toLowerCase();g[s]&amp;&amp;(i=s),n&amp;&amp;(g[s]=n,i=s);var u=e.split(&quot;-&quot;);if(!i&amp;&amp;u.length&gt;1)return t(u[0])}else{var a=e.name;g[a]=e,i=a}return!r&amp;&amp;i&amp;&amp;(m=i),i||!r&amp;&amp;m},S=function(t,e){if(p(t))return t.clone();var n=&quot;object&quot;==typeof e?e:{};return n.date=t,n.args=arguments,new O(n)},w=M;w.l=D,w.i=p,w.w=function(t,e){return S(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var O=function(){function y(t){this.$L=D(t.locale,null,!0),this.parse(t)}var v=y.prototype;return v.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(w.u(e))return new Date;if(e instanceof Date)return new Date(e);if(&quot;string&quot;==typeof e&amp;&amp;!/Z$/i.test(e)){var r=e.match(l);if(r){var i=r[2]-1||0,s=(r[7]||&quot;0&quot;).substring(0,3);return n?new Date(Date.UTC(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)):new Date(r[1],i,r[3]||1,r[4]||0,r[5]||0,r[6]||0,s)}}return new Date(e)}(t),this.$x=t.x||{},this.init()},v.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},v.$utils=function(){return w},v.isValid=function(){return!(this.$d.toString()===d)},v.isSame=function(t,e){var n=S(t);return this.startOf(e)&lt;=n&amp;&amp;n&lt;=this.endOf(e)},v.isAfter=function(t,e){return S(t)&lt;this.startOf(e)},v.isBefore=function(t,e){return this.endOf(e)&lt;S(t)},v.$g=function(t,e,n){return w.u(t)?this[e]:this.set(n,t)},v.unix=function(){return Math.floor(this.valueOf()/1e3)},v.valueOf=function(){return this.$d.getTime()},v.startOf=function(t,e){var n=this,f=!!w.u(e)||e,d=w.p(t),l=function(t,e){var r=w.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return f?r:r.endOf(u)},$=function(t,e){return w.w(n.toDate()[t].apply(n.toDate(&quot;s&quot;),(f?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},y=this.$W,v=this.$M,M=this.$D,m=&quot;set&quot;+(this.$u?&quot;UTC&quot;:&quot;&quot;);switch(d){case h:return f?l(1,0):l(31,11);case o:return f?l(1,v):l(0,v+1);case a:var g=this.$locale().weekStart||0,p=(y&lt;g?y+7:y)-g;return l(f?M-p:M+(6-p),v);case u:case c:return $(m+&quot;Hours&quot;,0);case s:return $(m+&quot;Minutes&quot;,1);case i:return $(m+&quot;Seconds&quot;,2);case r:return $(m+&quot;Milliseconds&quot;,3);default:return this.clone()}},v.endOf=function(t){return this.startOf(t,!1)},v.$set=function(t,e){var a,f=w.p(t),d=&quot;set&quot;+(this.$u?&quot;UTC&quot;:&quot;&quot;),l=(a={},a[u]=d+&quot;Date&quot;,a[c]=d+&quot;Date&quot;,a[o]=d+&quot;Month&quot;,a[h]=d+&quot;FullYear&quot;,a[s]=d+&quot;Hours&quot;,a[i]=d+&quot;Minutes&quot;,a[r]=d+&quot;Seconds&quot;,a[n]=d+&quot;Milliseconds&quot;,a)[f],$=f===u?this.$D+(e-this.$W):e;if(f===o||f===h){var y=this.clone().set(c,1);y.$d[l]($),y.init(),this.$d=y.set(c,Math.min(this.$D,y.daysInMonth())).$d}else l&amp;&amp;this.$d[l]($);return this.init(),this},v.set=function(t,e){return this.clone().$set(t,e)},v.get=function(t){return this[w.p(t)]()},v.add=function(n,f){var c,d=this;n=Number(n);var l=w.p(f),$=function(t){var e=S(d);return w.w(e.date(e.date()+Math.round(t*n)),d)};if(l===o)return this.set(o,this.$M+n);if(l===h)return this.set(h,this.$y+n);if(l===u)return $(1);if(l===a)return $(7);var y=(c={},c[i]=t,c[s]=e,c[r]=1e3,c)[l]||1,v=this.$d.getTime()+n*y;return w.w(v,this)},v.subtract=function(t,e){return this.add(-1*t,e)},v.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||d;var r=t||&quot;YYYY-MM-DDTHH:mm:ssZ&quot;,i=w.z(this),s=this.$H,u=this.$m,a=this.$M,o=n.weekdays,f=n.months,h=function(t,n,i,s){return t&amp;&amp;(t[n]||t(e,r))||i[n].slice(0,s)},c=function(t){return w.s(s%12||12,t,&quot;0&quot;)},l=n.meridiem||function(t,e,n){var r=t&lt;12?&quot;AM&quot;:&quot;PM&quot;;return n?r.toLowerCase():r},y={YY:String(this.$y).slice(-2),YYYY:this.$y,M:a+1,MM:w.s(a+1,2,&quot;0&quot;),MMM:h(n.monthsShort,a,f,3),MMMM:h(f,a),D:this.$D,DD:w.s(this.$D,2,&quot;0&quot;),d:String(this.$W),dd:h(n.weekdaysMin,this.$W,o,2),ddd:h(n.weekdaysShort,this.$W,o,3),dddd:o[this.$W],H:String(s),HH:w.s(s,2,&quot;0&quot;),h:c(1),hh:c(2),a:l(s,u,!0),A:l(s,u,!1),m:String(u),mm:w.s(u,2,&quot;0&quot;),s:String(this.$s),ss:w.s(this.$s,2,&quot;0&quot;),SSS:w.s(this.$ms,3,&quot;0&quot;),Z:i};return r.replace($,(function(t,e){return e||y[t]||i.replace(&quot;:&quot;,&quot;&quot;)}))},v.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},v.diff=function(n,c,d){var l,$=w.p(c),y=S(n),v=(y.utcOffset()-this.utcOffset())*t,M=this-y,m=w.m(this,y);return m=(l={},l[h]=m/12,l[o]=m,l[f]=m/3,l[a]=(M-v)/6048e5,l[u]=(M-v)/864e5,l[s]=M/e,l[i]=M/t,l[r]=M/1e3,l)[$]||M,d?m:w.a(m)},v.daysInMonth=function(){return this.endOf(o).$D},v.$locale=function(){return g[this.$L]},v.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=D(t,e,!0);return r&amp;&amp;(n.$L=r),n},v.clone=function(){return w.w(this.$d,this)},v.toDate=function(){return new Date(this.valueOf())},v.toJSON=function(){return this.isValid()?this.toISOString():null},v.toISOString=function(){return this.$d.toISOString()},v.toString=function(){return this.$d.toUTCString()},y}(),_=O.prototype;return S.prototype=_,[[&quot;$ms&quot;,n],[&quot;$s&quot;,r],[&quot;$m&quot;,i],[&quot;$H&quot;,s],[&quot;$W&quot;,u],[&quot;$M&quot;,o],[&quot;$y&quot;,h],[&quot;$D&quot;,c]].forEach((function(t){_[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),S.extend=function(t,e){return t.$i||(t(e,O,S),t.$i=!0),S},S.locale=D,S.isDayjs=p,S.unix=function(t){return S(1e3*t)},S.en=g[m],S.Ls=g,S.p={},S}()}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var s=e[r]={exports:{}};return t[r].call(s.exports,s,s.exports,n),s.exports}n.d=(t,e)=&gt;{for(var r in e)n.o(e,r)&amp;&amp;!n.o(t,r)&amp;&amp;Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=&gt;Object.prototype.hasOwnProperty.call(t,e),n.r=t=&gt;{&quot;undefined&quot;!=typeof Symbol&amp;&amp;Symbol.toStringTag&amp;&amp;Object.defineProperty(t,Symbol.toStringTag,{value:&quot;Module&quot;}),Object.defineProperty(t,&quot;__esModule&quot;,{value:!0})};var r={};(()=&gt;{&quot;use strict&quot;;n.r(r),n.d(r,{dayjs:()=&gt;t});const t=n(484)})(),Dayjs=r})();
  </code></pre>
  <p>Error from Appscript:</p>
  <pre><code>Error
  TypeError: Cannot destructure property 'dayjs' of 'Dayjs' as it is undefined.
  (anonymous)
  @ 
  </code></pre>