Reputation: 1656
I am working on my first Vue 3 project after using Vue 2 for a long time.
Normally in my components on Vue 2 projects I can import a library, for example moment, like so:
<script>
const moment = require("moment")
export default {
...
</script>
In vue 3, I'm trying to do the same:
<script setup>
const moment = require("moment")
</script>
However I get the error
Uncaught ReferenceError: require is not defined
How can I get around this and import modules into a vue3 component?
Upvotes: 1
Views: 8165
Reputation: 23500
You cann't use require
in Vite, did you try with import:
<script setup>
import moment from 'moment'
Upvotes: 3