question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom type components won't render in static nuxt build

See original GitHub issue

Version

module: 0.9.1 nuxt: ^2.15.3

Nuxt configuration

mode:

  • universal
  • spa

Nuxt configuration

Static generation

Reproduction

Custom components for custom types will work in dev mode, but will not generate for static.

What is expected?

Custom block types should be created in static site generation, just like dev mode

What is actually happening?

Errors from any kind of asyncData or fetch happening on server to build site throwing up:

WARN  Cannot stringify a function String
WARN  Cannot stringify a function Object
WARN  Cannot stringify a function render
WARN  Cannot stringify a function hook
WARN  Cannot stringify a function VueComponent

Steps to reproduce

  • Add @nuxtjs/sanity to a fresh Nuxt boilerplate
  • Fetch sanity content that contains a custom type
  • Confirm it works in dev mode
  • Run nuxt generate && nuxt start
  • You should see similar above errors and the custom components aren’t rendered in pages

Additional information

Checklist

  • I have tested with the latest Nuxt version and the issue still occurs
  • I have tested with the latest module version and the issue still occurs
  • I have searched the issue tracker and this issue hasn’t been reported yet

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
monowalescommented, Aug 6, 2021

Hi @danielroe, thanks for getting back on this. I found I had two problems, when trying the nuxt module it was fetch vs asyncData, and when trying the @rdunk sanity-blocks-vue-component I was mistakenly leaving ... mode: client } for the plugin in nuxt.config.js, which meant SSR didn’t have access to the component on generation. Thanks again for your help.

0reactions
danielroecommented, May 15, 2021

Just looking at your comment again, the key difference is that fetch stringifies the entire component state, whereas asyncData just stringifies what asyncData returns. I suspect you have set a data property to a component. Likely you can fix by setting in created() instead (with an added performance benefit as it won’t be reactive) or via a computed property. For example:

import MyComponent from './MyComponent.vue'
const MyDynamicComponent = () => import('./MyDynamicComponent.vue')

export default {
  created() {
    this.serializers = {
      types: {
        otherThing: MyComponent,
        dynamicThing: MyDynamicComponent,
      }
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom type components won't render in static nuxt build #123
I found I had two problems, when trying the nuxt module it was fetch vs asyncData , and when trying the @rdunk sanity-blocks-vue-component...
Read more >
Static directory - Nuxt
The static directory is directly mapped to the server root () and contains files that likely won't be changed. All included files will...
Read more >
Nuxt not rendering html for components - vue.js - Stack Overflow
I'm building an online shop using nuxt and nuxt generate for ... but I guess it should render the components since it's a...
Read more >
Creating Server-side Rendered Vue.js Apps Using Nuxt.js
When initially loading your website, your browser doesn't receive a complete page to display. Instead, it gets a bunch of pieces and instructions...
Read more >
Web Components in Server-Side Rendered (SSR) and Static ...
Below, I'm going to show you how to pre-render custom web components in Next.js. By extracting the logic used to create the template...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found