nuxt / nuxt/module-builder

Error: _mergeDefaults is not defined (in ^1.0)

Open
#649 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
275
Forks
35
Avg merge
4h 42m
Merged PRs (30d)
6

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked nuxt-module-builder-issue reproduction and compare the prepack playground path with dev:prepare. Inspect the generated component code around the imported propDefaults and _mergeDefaults call; done means the published-module path no longer produces an undefined helper while preserving imported prop defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxtjs, typescript
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.