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

vue-moment + nuxt (webpack) #44

Closed
marcpaskell opened this issue Oct 10, 2017 · 8 comments
Closed

vue-moment + nuxt (webpack) #44

marcpaskell opened this issue Oct 10, 2017 · 8 comments

Comments

@marcpaskell
Copy link

It looks like the most recent release of moment 2.19.0 has caused issues with vue-moment and webpack...

[web - 93095]: WARNING Compiled with 1 warnings4:56:47 PM
[web - 93095]: This relative module was not found:
[web - 93095]: * ./locale in ./node_modules/moment/src/lib/locale/locales.js

Does anyone have a workaround for this?

@goaround
Copy link

+1 without nuxt

@bryantwong
Copy link

bryantwong commented Oct 10, 2017

Here's the moment issue: moment/moment#4216

EDIT: Might be more elegant to just downgrade for now, here's what I did
npm uninstall moment --save-dev
npm install moment@2.18.1 --save-dev

I made a pull request here to fix it for now, but might not be necessary if moment.js fixes it first: #45

We have the same issue - for now this workaround seems to work: moment/moment#2979 (comment)

@bryantwong
Copy link

The moment.js guys just pushed a new build (moment/moment@29afed6) that seems to solves the ./locale issues.

@blowsie
Copy link

blowsie commented Dec 11, 2018

For anyone wanting to use nuxt
I did the following.

  1. Install and configure https://github.com/nuxt-community/moment-module
  2. Register a custom plugin which uses vue-moment code but with app.$moment context

plugins/moment-filters.js

import Vue from 'vue'

export default ({ app }) => {
  const moment = app.$moment
  Vue.filter('moment', (...args) => {
    ....
    return date
  })

  Vue.filter('duration', (...args) => {
    .....
    return duration
  })
}

@BrockReece
Copy link
Collaborator

@blowsie thanks for your input but I'm not sure this is relevant to the thread.

And I have been using this library with Nuxt without issue, what does your configuration solve?
For reference, my plugin is as simple as...

import Vue from 'vue'
import VueMoment from 'vue-moment'

Vue.use(VueMoment)

@blowsie
Copy link

blowsie commented Dec 11, 2018

@BrockReece in your example the instance of moment is not available in nuxt context such as context.app.$moment

@BrockReece
Copy link
Collaborator

Ok, I see, would something like this work?

import Vue from 'vue'
import VueMoment from 'vue-moment'

export default ({ app }) => {
  Vue.use(VueMoment)
  app.$moment = Vue.moment
})

Just to clarify though, is your solution is to add the code from the vue-moment plugin directly to your plugin file?

@blowsie
Copy link

blowsie commented Dec 12, 2018

Yes because other wise the following code from vue-moment will throw errors.

    Object.defineProperties(Vue.prototype, {
      $moment: {
        get() {
          return moment;
        },
      },
    });

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

6 participants