How to use moment.js in pug? Property or method "moment" is not defined on the instance but referenced during render

Viewed 124

I am using PugJs, VueJs and MomentJs to format my date. This project is not a Single File Component.

Here is my code

div {{ moment(currentEvent.date).format('DD MMMM YYYY')  }}

I have already added the library

script(src!= ASSET_PATH.js + "/vendor/moment.min.js")  

But when I run, I got the error:

enter image description here

1 Answers

I don't think that including the library inside the <template> </template> will work, it's not a pug problem.

Try this:

1 - Delete this line script(src!= ASSET_PATH.js + "/vendor/moment.min.js").

2 - Install momentjs with npm or yarn.

3 - now at the top inside the <script> </script> import it like so: import moment from 'moment'

Related