Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Error: _mergeDefaults is not defined (in ^1.0)

Đang mở
#649 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Một pull request liên quan đã được merge.

  • #328 của @Teages — đã merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
nuxtjs, typescript
Lĩnh vực
build-system

Hướng nghiên cứu

Bắt đầu với bản tái hiện nuxt-module-builder-issue được liên kết và so sánh prepack playground path với dev:prepare. Kiểm tra mã component được tạo xung quanh propDefaults đã import và lời gọi _mergeDefaults; hoàn thành khi published-module path không còn tạo ra một helper undefined và vẫn giữ nguyên các giá trị mặc định của prop đã import.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
277
Fork
36
Merge trung bình
4 ngày 19 giờ
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của nuxt/module-builder

Tất cả issue của nuxt/module-builder

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.