Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Error: _mergeDefaults is not defined (in ^1.0)

未关闭
#649 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

已经有一个关联 PR 被合并了。

  • #328 来自 @Teages —— 已合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
nuxtjs, typescript
领域
build-system

调研方向

从链接的 nuxt-module-builder-issue 复现开始,并将 prepack playground path 与 dev:prepare 进行比较。检查生成的组件代码中围绕导入的 propDefaults 和 _mergeDefaults 调用的部分;完成标准是 published-module path 不再产生 undefined helper,同时保留导入的 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
平均合并
2 小时 46 分钟
30 天内合并 PR
2

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

nuxt/module-builder 的其他 Issue

查看 nuxt/module-builder 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。