Vue.js: dev works but build+preview fails

I have a Vite + Vue.js 3 poryect in typescript and when I do npm run dev and enter in http://localhost:5173/ everithing works, but when I do npm run build && npm run preview and enter in http://localhost:4173/ the web give me a this javascript error TypeError: is undefined, which is impossible to debug because of all code have been minimized.

I though that is something works in dev, it should be work in build + preview.

  1. Am I missing something or skipping some mandatory step?
  2. How can I build my project whiteout minimized?

UPDATE: I have this method in a store:

storemap.$subscribe((mutation, state) => {
  if (map == null) return;
  if ( != "layer" || ==
  console.log("storemap.layer", storemap.layer);

I have added in the second if this condition == null || and TypeError: is undefined disappeared (although the web is still not working).

It is very difficult debug in this way. Is there any better way?

You need to add more type checking…

Have a read about falsey values if the following doesn’t make sense.

if (mutation && && ( !== "layer" || ===

or the modern approach using optional chaining.

if (
    mutation?.events.key !== "layer" ||
    mutation?.events.newValue === mutation?.events.oldValue

Finally the problem was events is only available in dev Interface: SubscriptionCallbackMutationPatchObject | Pinia