Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Error: _mergeDefaults is not defined (in ^1.0)

オープン
#649 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

関連するプルリクエストがすでにマージされています。

  • #328 @Teages による — マージ済み

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
nuxtjs, typescript
領域
build-system

調査の方向性

リンクされている nuxt-module-builder-issue の再現から始め、prepack playground path と dev:prepare を比較します。import された propDefaults と _mergeDefaults の呼び出し周辺にある生成されたコンポーネントコードを調べます。完了条件は、published-module path で undefined のヘルパーが生成されなくなり、import された prop defaults が維持されることです。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
277
フォーク
36
平均マージ
4日 19時間
マージ済み PR(30日)
3

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nuxt/module-builder のほかの issue

nuxt/module-builder の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。