For anyone else who has this issue in the future. I found alternative props than v-model="tags". I changed this to :list="tags" and all is working in both dev and prod mode. Very odd though that it only seemed to break after running npm run build!
Aug 24, 2022
2
Level 7
JS error after running npm run build. No error when testing in npm run dev
Hey all!
Not sure if this is more related to the Vue or Vite category but I'm getting an odd JS error after running npm run build. Everything works perfectly when in dev mode (npm run dev) but after compiling for deployment one part of the JS stops working.
This is the stripped back broken code. Notice that I am doing v-model on a prop "tags".
<script setup>
import draggable from 'vuedraggable';
const props = defineProps({
tags: Array,
});
</script>
<template>
<div v-if="tags.length > 0">
<table class="table">
<thead>
<th colspan="2" class="text-left">Tag</th>
</thead>
<draggable
v-model="tags"
@start="drag=true"
@end="drag=false; updateOrder(tagModel, tags);"
item-key="id"
tag="tbody"
>
<template #item="{element}">
<tr>
<td>
<div class="flex items-center">
{{ element.name }}
</div>
</td>
<td>{{ element.slug }}</td>
</tr>
</template>
</draggable>
</table>
</div>
</template>
When running the above I get undefined variable 'tags' after running npm run build. In dev mode though, this works fine.
Does anyone know why npm run dev and npm run build are having different results?
Thanks!
Please or to participate in this conversation.