Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module-added component throws 'src.replace is not a function' if prefixed with Lazy and is not a vue file #23768

Closed
smastrom opened this issue Oct 18, 2023 · 5 comments · Fixed by #25286

Comments

@smastrom
Copy link

Environment

Stackblitz

Reproduction

https://stackblitz.com/edit/nuxt-starter-5f85qa?file=app.vue

Describe the bug

Given two components that produce the same output:

JsComponent.js

import { h, defineComponent } from 'vue'

export const JsComponent = defineComponent({
  render() {
    return h('div', null, this.$slots.default?.())
  },
})

VueComponent.vue

<template>
  <div><slot /></div>
</template>

Added to the Nuxt app via addComponent in a Nuxt module definition:

addComponent({
  name: 'JsComponent',
  export: 'JsComponent',
  filePath: resolve('./JsComponent.js'),
})

addComponent({
  name: 'VueComponent',
  filePath: resolve('./VueComponent.vue'),
})

If prefixed with Lazy:

<template>
  <LazyVueComponent>Hello</LazyVueComponent>
  <LazyJsComponent>Hello</LazyJsComponent>
</template>

The .vue one works as expected, the .js one throws the following SSR error: src.replace is not a function.

After dealing with this a bit, I found out that if the js component has no child, it doesn't throw any error:

<LazyJsComponent></LazyJsComponent>

But even a single char or a comment will break things again.

Additional context

No response

Logs

[Vue warn]: Invalid vnode type when creating vnode: undefined.
[nuxt] [request error] [unhandled] [500] src.replace is not a function
@stackblitz
Copy link

stackblitz bot commented Oct 18, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@huang-julien
Copy link
Member

huang-julien commented Oct 19, 2023

hmmm seems like doing a default export in the JS file can be a workaround. Will take a look a bit later 🤔 .
Not sure if it's a vue core or nuxt bug atm

@Xzandro
Copy link

Xzandro commented Dec 10, 2023

I encountered a similar issue with dynamic components that have a slot.

<component :is="components[block.__component]" :block="block" :page="page">
   <Headline/>
</component>

Will throw the exact error message. Even when I set a simple string instead of the headline component, it will cause this error. Kind of blocking for me, is there any workaround for this? I could wrap these in <ClientOnly>, but this defeats the purpose of SSR.

@Xzandro
Copy link

Xzandro commented Jan 31, 2024

When using my case, this unfortunately does not fix the error even on nuxt 3.10.0.

@danielroe
Copy link
Member

@Xzandro would you create a new issue with a reproduction? 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants