Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Error: _mergeDefaults is not defined (in ^1.0)

Aperta
#649 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Una pull request collegata è già stata integrata.

  • #328 di @Teages — integrata

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
nuxtjs, typescript
Ambito
build-system

Direzione di ricerca

Inizia con la riproduzione collegata di nuxt-module-builder-issue e confronta il percorso del playground di prepack con dev:prepare. Ispeziona il codice del componente generato intorno ai propDefaults importati e alla chiamata a _mergeDefaults; il lavoro è completato quando il percorso del published-module non produce più un helper undefined e preserva i valori predefiniti delle props importati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

I updated a module to use 1.0 and kept getting this error when actually using it. Version 0.8 works fine. Managed to replicate the issue, here's the repo (prepack + dev playground). Note I set the playground to link the parent module and use it as if it were a real dep, otherwise I can't replicate. In a real app, using a real published module I can also replicate.

Interestingly, using dev:prepare does not have the same issue.

The issue happens if a component imports an object and uses it as the defaults for a prop, the outputted code looks like this:

<script setup>
import { propDefaults } from "./defaults.js";
defineProps(/* @__PURE__ */ _mergeDefaults({
  color: { type: String, required: false },
  disabled: { type: Boolean, required: false }
}, {
  color: "blue",
  ...propDefaults
}));
</script>

If I remove propDefaults, because withDefaults is transformed away it works:

defineProps({
  color: { type: String, required: false, default: "blue" },
  disabled: { type: Boolean, required: false, default: false }
});

With 0.8 it used to just looked like this and worked fine:

<script setup  lang="ts">
import { propDefaults } from './defaults.js'

withDefaults(defineProps<{
  color?: string
  disabled?: boolean
}>(), {
  color: 'blue',
  ...propDefaults,
})
</script>

I know component's can't reference local objects because withDefaults is a compiler macro, but they can reference imports like this. Or at least, this had been working fine for me for a long time and I checked and it works fine on the Vue SFC playground too.

Lingua principale
TypeScript
Stelle
277
Fork
36
Merge medio
4g 19h
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nuxt/module-builder

Tutte le issue di nuxt/module-builder

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.