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

this.$moment.locale an this.$moment.updateLocale - TypeError - not a function (v2.24.0 and later) #5844

Open
fwiwDev opened this issue Mar 11, 2021 · 0 comments

Comments

@fwiwDev
Copy link

fwiwDev commented Mar 11, 2021

Describe the bug
Using moment.locale() or moment.updateLocale() causes an error, "TypeError: this.$moment.locale is not a function" or "TypeError: this.$moment.updateLocale is not a function"

To Reproduce
Steps to reproduce the behavior:

  1. Go to a minimal repo with reproducible code: https://github.com/fwiwDev/ally-debug (gh repo clone fwiwDev/ally-debug)
  2. run > yarn
  3. run > quasar dev -m electron
  4. Open console
  5. See error in console
vue.runtime.esm.js?5593:1888 TypeError: this.$moment.locale is not a function
    at VueComponent.created (App.vue?234e:15)
    at invokeWithErrorHandling (vue.runtime.esm.js?5593:1854)
    at callHook (vue.runtime.esm.js?5593:4219)
    at VueComponent.Vue._init (vue.runtime.esm.js?5593:5008)
    at new VueComponent (vue.runtime.esm.js?5593:5154)
    at createComponentInstanceForVnode (vue.runtime.esm.js?5593:3283)
    at init (vue.runtime.esm.js?5593:3114)
    at createComponent (vue.runtime.esm.js?5593:5978)
    at createElm (vue.runtime.esm.js?5593:5925)
    at Vue.patch [as __patch__] (vue.runtime.esm.js?5593:6516)

Expected behavior
Expecting the locale of my moment object to be set.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10
  • Electron
  • Version 2004

Moment-specific environment

  • The time zone setting of the machine the code is running on: UTC-06:00
  • The time and date at which the code was run: 3/11/2021, 11:20 AM
  • Other libraries in use (TypeScript, Immutable.js, etc)
  "dependencies": {
    "@quasar/cli": "^1.1.3",
    "@quasar/extras": "^1.9.8",
    "eslint-plugin-vue": "^6.2.2",
    "moment": "2.4.0",
    "quasar": "^1.14.1",
    "vcards-js": "^2.10.0",
    "vue-croppa": "^1.3.8",
    "vue-css-donut-chart": "^1.3.0",
    "vue-i18n": "^8.23.0",
    "vuedraggable": "^2.23.2"
  },
  "devDependencies": {
    "@quasar/app": "^2.0.0",
    "babel-eslint": "^10.0.1",
    "devtron": "^1.4.0",
    "electron": "^9.0.0",
    "electron-debug": "^3.0.1",
    "electron-devtools-installer": "^3.0.0",
    "eslint": "^6.8.0",
    "eslint-config-prettier": "^6.9.0",
    "eslint-loader": "^3.0.3"
  },

Please run the following code in your environment and include the output:

console.log((new Date()).toString())
console.log((new Date()).toLocaleString())
console.log((new Date()).getTimezoneOffset())
console.log(navigator.userAgent)
console.log(this.$moment.version)

please see below:

App.vue?234e:11 Thu Mar 11 2021 11:28:57 GMT-0600 (Central Standard Time)
App.vue?234e:12 3/11/2021, 11:28:57 AM
App.vue?234e:13 360
App.vue?234e:14 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.122 Electron/9.4.4 Safari/537.36
App.vue?234e:15 2.4.0

Additional context
Add any other context about the problem here.
Quasar is setup to have moment as a global accessible as this.$moment. This is done in the quasar.conf.js in the boot area corresponds to the file at src/boot/moment.js.
Even without this global setup, I am still getting this:

vue.runtime.esm.js?5593:1888 TypeError: moment__WEBPACK_IMPORTED_MODULE_0___default.a.locale is not a function
    at VueComponent.created (App.vue?234e:19)
    at invokeWithErrorHandling (vue.runtime.esm.js?5593:1854)
    at callHook (vue.runtime.esm.js?5593:4219)
    at VueComponent.Vue._init (vue.runtime.esm.js?5593:5008)
    at new VueComponent (vue.runtime.esm.js?5593:5154)
    at createComponentInstanceForVnode (vue.runtime.esm.js?5593:3283)
    at init (vue.runtime.esm.js?5593:3114)
    at createComponent (vue.runtime.esm.js?5593:5978)
    at createElm (vue.runtime.esm.js?5593:5925)
    at Vue.patch [as __patch__] (vue.runtime.esm.js?5593:6516)

with these changes in App.vue:

  created () {
    console.log((new Date()).toString())
    console.log((new Date()).toLocaleString())
    console.log((new Date()).getTimezoneOffset())
    console.log(navigator.userAgent)
    console.log(moment.version)
    moment.locale(this.$i18n.locale)
  },
  computed: {
    currentTime () {
      return moment().format('LL')
    }
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant