Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.9.2 crashes with "TypeError: t is not a function" #1132

Closed
medikoo opened this issue Oct 13, 2020 · 14 comments · Fixed by #1133
Closed

v1.9.2 crashes with "TypeError: t is not a function" #1132

medikoo opened this issue Oct 13, 2020 · 14 comments · Fixed by #1133
Labels

Comments

@medikoo
Copy link

medikoo commented Oct 13, 2020

Describe the bug

I've just upgraded from v1.9.1 to v1.9.2 (just released) and following started to crash

const dayjs = require('dayjs');
dayjs.extend(require('dayjs/plugin/localizedFormat'));

Error:

usr/local/lib/node_modules/dayjs/dayjs.min.js:1
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.dayjs=e()}(this,function(){"use strict";var t="millisecond",e="second",n="minute",r="hour",i="day",s="week",u="month",a="quarter",o="year",f="date",h=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?.?(\d+)?$/,c=/\[([^\]]+)]|Y{2,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,d={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},$=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},l={s:$,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),i=n%60;return(e<=0?"+":"-")+$(r,2,"0")+":"+$(i,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),i=e.clone().add(r,u),s=n-i<0,a=e.clone().add(r+(s?-1:1),u);return+(-(r+(n-i)/(s?i-a:a-i))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(h){return{M:u,y:o,w:s,d:i,D:f,h:r,m:n,s:e,ms:t,Q:a}[h]||String(h||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},y="en",M={};M[y]=d;var m=function(t){return t instanceof S},D=function(t,e,n){var r;if(!t)return y;if("string"==typeof t)M[t]&&(r=t),e&&(M[t]=e,r=t);else{var i=t.name;M[i]=t,r=i}return!n&&r&&(y=r),r||!n&&y},v=function(t,e){if(m(t))return t.clone();var n="object"==typeof e?e:{};return n.date=t,n.args=arguments,new S(n)},g=l;g.l=D,g.i=m,g.w=function(t,e){return v(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var S=function(){function d(t){this.$L=this.$L||D(t.locale,null,!0),this.parse(t)}var $=d.prototype;return $.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(g.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(h);if(r){var i=r[2]-1||0,s=(r[7]||"0").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()},$.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()},$.$utils=function(){return g},$.isValid=function(){return!("Invalid Date"===this.$d.toString())},$.isSame=function(t,e){var n=v(t);return this.startOf(e)<=n&&n<=this.endOf(e)},$.isAfter=function(t,e){return v(t)<this.startOf(e)},$.isBefore=function(t,e){return this.endOf(e)<v(t)},$.$g=function(t,e,n){return g.u(t)?this[e]:this.set(n,t)},$.unix=function(){return Math.floor(this.valueOf()/1e3)},$.valueOf=function(){return this.$d.getTime()},$.startOf=function(t,a){var h=this,c=!!g.u(a)||a,d=g.p(t),$=function(t,e){var n=g.w(h.$u?Date.UTC(h.$y,e,t):new Date(h.$y,e,t),h);return c?n:n.endOf(i)},l=function(t,e){return g.w(h.toDate()[t].apply(h.toDate("s"),(c?[0,0,0,0]:[23,59,59,999]).slice(e)),h)},y=this.$W,M=this.$M,m=this.$D,D="set"+(this.$u?"UTC":"");switch(d){case o:return c?$(1,0):$(31,11);case u:return c?$(1,M):$(0,M+1);case s:var v=this.$locale().weekStart||0,S=(y<v?y+7:y)-v;return $(c?m-S:m+(6-S),M);case i:case f:return l(D+"Hours",0);case r:return l(D+"Minutes",1);case n:return l(D+"Seconds",2);case e:return l(D+"Milliseconds",3);default:return this.clone()}},$.endOf=function(t){return this.startOf(t,!1)},$.$set=function(s,a){var h,c=g.p(s),d="set"+(this.$u?"UTC":""),$=(h={},h[i]=d+"Date",h[f]=d+"Date",h[u]=d+"Month",h[o]=d+"FullYear",h[r]=d+"Hours",h[n]=d+"Minutes",h[e]=d+"Seconds",h[t]=d+"Milliseconds",h)[c],l=c===i?this.$D+(a-this.$W):a;if(c===u||c===o){var y=this.clone().set(f,1);y.$d[$](l),y.init(),this.$d=y.set(f,Math.min(this.$D,y.daysInMonth())).$d}else $&&this.$d[$](l);return this.init(),this},$.set=function(t,e){return this.clone().$set(t,e)},$.get=function(t){return this[g.p(t)]()},$.add=function(t,a){var f,h=this;t=Number(t);var c=g.p(a),d=function(e){var n=v(h);return g.w(n.date(n.date()+Math.round(e*t)),h)};if(c===u)return this.set(u,this.$M+t);if(c===o)return this.set(o,this.$y+t);if(c===i)return d(1);if(c===s)return d(7);var $=(f={},f[n]=6e4,f[r]=36e5,f[e]=1e3,f)[c]||1,l=this.$d.getTime()+t*$;return g.w(l,this)},$.subtract=function(t,e){return this.add(-1*t,e)},$.format=function(t){var e=this;if(!this.isValid())return"Invalid Date";var n=t||"YYYY-MM-DDTHH:mm:ssZ",r=g.z(this),i=this.$locale(),s=this.$H,u=this.$m,a=this.$M,o=i.weekdays,f=i.months,h=function(t,r,i,s){return t&&(t[r]||t(e,n))||i[r].substr(0,s)},d=function(t){return g.s(s%12||12,t,"0")},$=i.meridiem||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r},l={YY:String(this.$y).slice(-2),YYYY:this.$y,M:a+1,MM:g.s(a+1,2,"0"),MMM:h(i.monthsShort,a,f,3),MMMM:h(f,a),D:this.$D,DD:g.s(this.$D,2,"0"),d:String(this.$W),dd:h(i.weekdaysMin,this.$W,o,2),ddd:h(i.weekdaysShort,this.$W,o,3),dddd:o[this.$W],H:String(s),HH:g.s(s,2,"0"),h:d(1),hh:d(2),a:$(s,u,!0),A:$(s,u,!1),m:String(u),mm:g.s(u,2,"0"),s:String(this.$s),ss:g.s(this.$s,2,"0"),SSS:g.s(this.$ms,3,"0"),Z:r};return n.replace(c,function(t,e){return e||l[t]||r.replace(":","")})},$.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},$.diff=function(t,f,h){var c,d=g.p(f),$=v(t),l=6e4*($.utcOffset()-this.utcOffset()),y=this-$,M=g.m(this,$);return M=(c={},c[o]=M/12,c[u]=M,c[a]=M/3,c[s]=(y-l)/6048e5,c[i]=(y-l)/864e5,c[r]=y/36e5,c[n]=y/6e4,c[e]=y/1e3,c)[d]||y,h?M:g.a(M)},$.daysInMonth=function(){return this.endOf(u).$D},$.$locale=function(){return M[this.$L]},$.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=D(t,e,!0);return r&&(n.$L=r),n},$.clone=function(){return g.w(this.$d,this)},$.toDate=function(){return new Date(this.valueOf())},$.toJSON=function(){return this.isValid()?this.toISOString():null},$.toISOString=function(){return this.$d.toISOString()},$.toString=function(){return this.$d.toUTCString()},d}(),p=S.prototype;return v.prototype=p,[["$ms",t],["$s",e],["$m",n],["$H",r],["$W",i],["$M",u],["$y",o],["$D",f]].forEach(function(t){p[t[1]]=function(e){return this.$g(e,t[0],t[1])}}),v.extend=function(t,e){return t(e,S,v),v},v.locale=D,v.isDayjs=m,v.unix=function(t){return v(1e3*t)},v.en=M[y],v.Ls=M,v});

TypeError: t is not a function
    at Function.v.extend (/usr/local/lib/node_modules/dayjs/dayjs.min.js:1:6318)
    at Object.<anonymous> (/Users/medikoo/npm-packages/serverless/test.js:6:7)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47
                                                   

Expected behavior

No error should happen

Information

  • Day.js Version [e.g. v1.9.2]
  • OS: macOs 10.15.7
  • Node.js: v14.13.1
@Ali-Dalal
Copy link

same here
issue affecting serverless frameworks and some of the plugins like sls domain manager

can you please rollback the last version?

@iamkun
Copy link
Owner

iamkun commented Oct 13, 2020

Will check this ASAP

@iamkun
Copy link
Owner

iamkun commented Oct 13, 2020

v1.9.3 has fixed this bug. Sorry for the inconvenience.

iamkun pushed a commit that referenced this issue Oct 13, 2020
## [1.9.3](v1.9.2...v1.9.3) (2020-10-13)

### Bug Fixes

* fix localizedFormat export error ([#1133](#1133)) ([deecd6a](deecd6a)), closes [#1132](#1132)
@iamkun
Copy link
Owner

iamkun commented Oct 13, 2020

🎉 This issue has been resolved in version 1.9.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@SMCDanPat
Copy link

Thanks for the quick fix @iamkun, appreciated.

@medikoo
Copy link
Author

medikoo commented Oct 13, 2020

Great thanks @iamkun for fast response!

Do you plan to improve a release flow to avoid such issues in a feature? e.g. by building in CI, verifying the build and only after that passes releasing a new version in context of a CI?

@iamkun
Copy link
Owner

iamkun commented Oct 13, 2020

@medikoo sure. All of the release work is made by CI in an auto workflow atm. Just wondering if we should make a test build in each PR to avoid this.

@medikoo
Copy link
Author

medikoo commented Oct 13, 2020

if we should make a test build in each PR to avoid this.

I believe there should be test build prior npm publish it's what would prevent broken release

@iamkun
Copy link
Owner

iamkun commented Oct 13, 2020

This is just a rollup warning, that's why it did not stop the release.

@mahenzon
Copy link

mahenzon commented Jan 30, 2021

Having this issue when running jest tests:

dayjs 1.9.4
jest 24.9.0
FAIL  tests/unit/check.spec.js
  ● Test suite failed to run

    TypeError: t is not a function

      12 | import config from '@/config'
      13 | 
    > 14 | dayjs.extend(relativeTime)
         |       ^
      15 | dayjs.extend(localizedFormat)
      16 | dayjs.extend(isToday)
      17 | dayjs.extend(utc)

      at Object.extend (node_modules/dayjs/dayjs.min.js:1:6407)
      at Object.<anonymous> (src/helpers/formatters.js:14:7)
      at Object.<anonymous> (src/helpers/compliance.js:6:1)
      at Object.<anonymous> (tests/unit/check.spec.js:1:1)

dayjs is imported this way: import * as dayjs from 'dayjs'

UPD:
changed import to import dayjs from 'dayjs', now it works
thx to #475 (comment)

@LukasDeco
Copy link

I use rescript which compiles to js. It compiles imports like this:
import * as Dayjs from "dayjs";

As a result, my component using dayjs is untestable. When will a fix be put in that will allow me to import it using the *? Thanks!

andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this issue May 10, 2022
## [1.9.3](iamkun/dayjs@v1.9.2...v1.9.3) (2020-10-13)

### Bug Fixes

* fix localizedFormat export error ([#1133](iamkun/dayjs#1133)) ([deecd6a](iamkun/dayjs@deecd6a)), closes [#1132](iamkun/dayjs#1132)
andrewhood125ruhuc added a commit to andrewhood125ruhuc/SidRH2 that referenced this issue May 10, 2022
## [1.9.3](iamkun/dayjs@v1.9.2...v1.9.3) (2020-10-13)

### Bug Fixes

* fix localizedFormat export error ([#1133](iamkun/dayjs#1133)) ([deecd6a](iamkun/dayjs@deecd6a)), closes [#1132](iamkun/dayjs#1132)
@vitorLMR
Copy link

I have the same error in version 1.11.7

@master117
Copy link

I have the same error in version 1.11.7

Are you importing like this?

import * as weekOfYear from "dayjs/plugin/weekOfYear";

dayjs.extend(weekOfYear);

or like this?

import weekOfYear from "dayjs/plugin/weekOfYear";

dayjs.extend(weekOfYear);

The first causes the error for me on 1.11.10, the second doesn't.

@lidorcg
Copy link

lidorcg commented Oct 31, 2024

I think I encounter the same error:

Uncaught TypeError: t2 is not a function
    at O.extend (dayjs.js?v=8128606f:277:26)

For me it's on 1.11.13 on vite + typescript.

And I saw here that there's a specific guide for this but it doesn't seem to work, i.e:
I don't have:

{ //tsconfig.json
  "compilerOptions": {
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
  }
}

In my tsconfig and yet...

import * as dayjs from "dayjs";
import * as dayjsUTC from "dayjs/plugin/utc";
dayjs.extend(dayjsUTC);

doesn't work

import dayjs from "dayjs";
import dayjsUTC from "dayjs/plugin/utc";
dayjs.extend(dayjsUTC);

works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants