admin管理员组文章数量:1430523
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'
本文标签: javascriptVue 3 quotUncaught ReferenceError require is not definedquotStack Overflow
版权声明:本文标题:javascript - Vue 3 "Uncaught ReferenceError: require is not defined" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745536751a2662306.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论