I am working on my first Vue 3 project after using Vue 2 for a long time.
Normally in my ponents 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 ponent?
I am working on my first Vue 3 project after using Vue 2 for a long time.
Normally in my ponents 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 ponent?
Share Improve this question edited Jul 1, 2022 at 13:08 Nikola Pavicevic 23.5k9 gold badges29 silver badges51 bronze badges asked Jun 29, 2022 at 15:57 corycorycorycorycorycory 1,6563 gold badges25 silver badges50 bronze badges 1- even on vue2, you should use import not require – Lk77 Commented Jul 1, 2022 at 13:13
1 Answer
Reset to default 3You cann't use require
in Vite, did you try with import:
<script setup>
import moment from 'moment'